I sent a user a TestFlight version of my app. She has a video recorded that she made using her iPhone. When the imagePicker was presented and she selected a video it came back as nil. I have an error message with a number 120 that appears in an alert that tells me where the error occurred.
It can only be the asset [UIImagePickerController.InfoKey.phAsset] as? PHAsset is nil. I don't see how that's possible because it's a video that she made using her phone. The odd thing is when she selects a photo everything works fine and when I select videos using iOS 14 and iOS 13 everything works fine.
She's on iOS 15.1, and I'm wondering is that the issue? She's a fellow iOS dev and she said iOS 15 has been causing issues.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let asset = info[UIImagePickerController.InfoKey.phAsset] as? PHAsset
// ...
if let style = asset?.playbackStyle {
// ...
// if it entered here then the below alert would have never appeared
} else {
let errorMessage = "Error: 120"
let alert = UIAlertController(title: "Unknown Error", message: errorMessage, preferredStyle: .alert)
// ...
}
imagePicker?.dismiss(animated: true, completion: nil)
}
FYI afterwards I just tested on iOS 15.1 with some videos and it worked fine.
I tried the PHPickerController but it's very buggy so I'd rather stick with the ImagePicker for now.
I'm not exactly sure how the asset can be nil but according to this answer by @Sh_Kahn I need to handle all possibilities: