3

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.

4

1 回答 1

4

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.

于 2018-02-05T21:35:01.687 回答