xcode 8 PHPhotoLibrary.requestAuthorization causing crash
Asked Answered
K

2

11

My app keeps crashing when running in the simulator everytime I try to request authorization for the photo library. I am using the following code in my appDelegate in didFinishLaunchingWithOptions:

if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.authorized {
     PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) in

     })
}

Using xcode 8 beta with swift 3.0.

Kachine answered 17/6, 2016 at 10:39 Comment(0)
G
24

In my testing, iOS 10 doesn't like to output useful error messages unless you're running on an actual device. In this particular case, you probably haven't provided the key NSPhotoLibraryUsageDescription in your Info.plist file, and that value must be provided before requesting authorization.

Gordy answered 17/6, 2016 at 19:44 Comment(5)
Thanks for your reply. I haven't spent too much time modifying my plist file. Is it as simple as pressing the plus and manually typing NSPhotoLibraryUsageDescription and selecting the type to String?. Also will this cause issues going forward? I thought that that property was a system property and could not be modified within an app other than by system alert acceptance.Kachine
Do those steps you said, then enter some text in the box to the right: "We need to read your photos so that we can grok some glerbs." This will be shown to the user to explain why you want access, and it's standard procedure in iOS. I'm writing a book on iOS 10 right now and the first chapter covers exactly this procedure.Gordy
That's great. Works perfectly. Thanks very much for your help.Kachine
Meanwhile I compile this, I would like to say thank you because I know this will solve my issue as well. Edit: It did!Nic
Any way to localize the value?Edwinedwina
D
3

Have to allow access to photos on device. Add below key and string to your info.plist. The autocomplete in the property list view is "Privacy - Photo Library Usage Description". Or just open your info.plist in source code view and add the following:

<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photos.</string>
Deposition answered 18/10, 2016 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.