Reputation: 401
I'm working in an app where a user has a profile picture. One of the remarks that someone had was that when you open the library, live pictures weren't shown. I tried adding the media type like this:
@IBAction func selectLibrary() {
let picker = UIImagePickerController()
picker.sourceType = .savedPhotosAlbum
picker.mediaTypes = ["kUTTypeImage","kUTTypeLivePhoto"]
picker.delegate = self
present(picker, animated: true)
}
However, when I did this, my app crashed, and it gave me the following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'No available types for source 2'
This was tested on an iPhone 7, running iOS 11.0 and an iPhone 8 plus, running iOS 11.2
Is there something I'm missing, perhaps some extra step I forgot when trying to use Live Photos?
Thanks.
Upvotes: 3
Views: 845
Reputation: 534950
The strings are not the same as the constants. Your code says:
picker.mediaTypes = ["kUTTypeImage","kUTTypeLivePhoto"]
Those are not valid media types. What you want to use is the constants:
picker.mediaTypes = [kUTTypeLivePhoto as String, kUTTypeImage as String]
You will need to import MobileCoreServices
to use the constants.
Upvotes: 4