I have a sample iOS 10 application requesting authorisation to the Photos Library and crashing on a real device with the following crash error:
PhotosAuthorizationCrashTest[2014:42551] [access] <private>
The repo can be found here
Here's the code that requests authorisation (Swift 3.0):
private func requestAuthorizationIfNeeded() {
DispatchQueue.main.async {
let status = PHPhotoLibrary.authorizationStatus()
if status == .authorized {
return
}
PHPhotoLibrary.requestAuthorization({ (status) in
if status == .authorized {
return
}
NSLog("Could not get authorization to access photos")
})
}
}
I've found the issue to be related with the fact that some Usage Description keys have become mandatory in iOS 10.
Even though
NSPhotoLibraryUsageDescription
has been around since iOS 6, it has only become a requirement in iOS 10, and the crash message wasn't very helpful.In the simulator of the latest Xcode (Xcode 8 beta 3 at the moment) the crash message is a bit more detailed, (even though on a device it is still the same):
So adding
NSPhotoLibraryUsageDescription
to myInfo.plist
file has fixed the issue.For more documentation, see Cocoa Keys
More specifically, the section named
NSPhotoLibraryUsageDescription
: