При использовании от self.imagePicker.mediaTypes = [(kUTTypeImage as String)]
до UIImagePicker
я могу выбрать все типы изображений, но мое требование - выбирать только изображения типа JPG, JPEG and PNG
через библиотеку фотографий, а GIF
и HEIC
(живые фотографии) не допускаются .
Итак, есть ли способ предотвратить выбор фотографий типа GIF и HEI C при imagePicker.sourceType = .photoLibrary
коде? :
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)
}
}
}
}))