Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode 8 PHPhotoLibrary.requestAuthorization causing crash

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.

like image 221
alionthego Avatar asked Jun 17 '16 10:06

alionthego


2 Answers

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.

like image 196
TwoStraws Avatar answered Oct 18 '22 20:10

TwoStraws


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>
like image 45
kelsheikh Avatar answered Oct 18 '22 19:10

kelsheikh