Hi All,
Sometime we have to take a picture using camera and use that image , we have to follow these simple steps.
1) Ask permission to access camera and microphone. Add these key and value in your project plist:-
<key>NSMicrophoneUsageDescription</key>
<string>This app does not require access to the microphone.</string>
<key>NSCameraUsageDescription</key>
<string>This app requires access to the camera.</string>
2) Add code to open camera to take picture :-
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = UIImagePickerControllerSourceType.camera;
imag.allowsEditing = true
imag.mediaTypes = [kUTTypeImage as String]
self.present(imag, animated: true, completion: nil)
}
3) Last step to use clicked image by user :-
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
print(info)
//you can use image in data variable as this image is one which user picked from gallery.
let data = UIImagePNGRepresentation(info[UIImagePickerControllerEditedImage] as! UIImage)
}
0 Comment(s)