While using self.imagePicker.mediaTypes = [(kUTTypeImage as String)] through UIImagePicker I am able to select all types of images but my requirement is select only JPG, JPEG and PNG type images through photo library and GIF and HEIC(live photos) are not allowed.
So, Is there any way by which I can prevent selecting GIFs and HEIC type photo while imagePicker.sourceType = .photoLibrary
Code:
imagePicker.delegate = self
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: StringConstants.Actions.Camera, style: .default, handler: { (action:UIAlertAction) in
CheckPermissions.checkPermission(permissionFor: .Camera,vc:self) { (success) in
if success {
DispatchQueue.main.async {[unowned self] in
if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)) {
self.view.endEditing(true)
self.imagePicker.allowsEditing = false
self.imagePicker.sourceType = UIImagePickerControllerSourceType.camera
self.imagePicker.cameraCaptureMode = .photo
self.imagePicker.showsCameraControls = true
self.imagePicker.modalPresentationStyle = .overFullScreen
self.present(self.imagePicker, animated: true, completion: nil)
}
else {
self.showAlert(withTitle: kEmptyString, message: StringConstants.AlertMessage.cameraAlertMessage, andOkAction: nil )
}
}
}
}
}))
actionSheet.addAction(UIAlertAction(title: StringConstants.Actions.PhotoLibrary, style: .default, handler: { (action:UIAlertAction) in
CheckPermissions.checkPermission(permissionFor: .PhotoLibrary,vc: self) { (success) in
if success {
DispatchQueue.main.async {[unowned self] in
self.view.endEditing(true)
self.imagePicker.allowsEditing = false
self.imagePicker.sourceType = .photoLibrary
self.imagePicker.modalPresentationStyle = .overFullScreen
self.imagePicker.navigationBar.isTranslucent = false
self.imagePicker.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
self.present(self.imagePicker, animated: true, completion: nil)
}
}
}
}))
Simply No. There is no way to give input of specific formate to UIImagePicker and get the result of only that formate.
UIImagePicker only accepts kUTTypeMovie and kUTTypeImage as a mediaType. What you can do is check the image/file extension after picking any image in didFinishPickingMediaWithInfo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With