ios - Determine if image picker media type is video or photo
12,187
Solution 1
Use this
if let mediaType = info[UIImagePickerControllerMediaType] as? String {
if mediaType == "public.image" {
print("Image Selected")
}
if mediaType == "public.movie" {
print("Video Selected")
}
}
Solution 2
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
}
Solution 3
if mediaType.isEqualToString(kUTTypeImage as String){
}
Worked :)
Author by
Salome Tsiramua
Updated on June 07, 2022Comments
-
Salome Tsiramua about 2 years
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