I have UIImagePickerController which is choosing photo or video from gallery, after selecting item, I want to determine which one is chosen, photo or video
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let mediaType = info[UIImagePickerControllerMediaType]
}
I've found this: How to select any Video or Movie file from UIImagePickerController
but could not translate to Swift:
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
}
thank you in advance
Use this
if let mediaType = info[UIImagePickerControllerMediaType] as? String {
if mediaType == "public.image" {
print("Image Selected")
}
if mediaType == "public.movie" {
print("Video Selected")
}
}
Swift 4. Use this:
guard info[UIImagePickerControllerMediaType] != nil else { return }
let mediaType = info[UIImagePickerControllerMediaType] as! CFString
switch mediaType {
case kUTTypeImage:
break
case kUTTypeMovie:
break
case kUTTypeLivePhoto:
break
default:
break
}
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