8

I have the following function that displays an action sheet with two different options. Currently, the only implemented option is the titled "Photos". The action sheet is presented correctly and the proper action gets called. My problem is that on the simulator and on an actual device, I can not get to display the prompt requesting access to the photo library.

PHPhotoLibrary.authorizationStatus() returns .Denied and presents the modal informing the current app does not have access to the photos: enter image description here

@IBAction func attachPhotoButtonTapped(sender: AnyObject) {
    let actionSheetController = UIAlertController(title: "Images", message: "Select image source...", preferredStyle: .ActionSheet)
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) {
        (action) in
        // ...
    }
    actionSheetController.addAction(cancelAction)

    let takePictureAction = UIAlertAction(title: "Camera", style: .Default) {
        (action) in
        // ...
    }
    actionSheetController.addAction(takePictureAction)

    let choosePictureAction = UIAlertAction(title: "Photos", style: .Default) {
        (action) in
        PHPhotoLibrary.requestAuthorization({(status:PHAuthorizationStatus) in
            switch status{
                case .Authorized:
                    dispatch_async(dispatch_get_main_queue(), {
                        print("Authorized")
                    })
                    break
                case .Denied:
                    dispatch_async(dispatch_get_main_queue(), {
                        print("Denied")
                    })
                    break
                default:
                    dispatch_async(dispatch_get_main_queue(), {
                        print("Default")
                    })
                    break
            }
        })
    }
    actionSheetController.addAction(choosePictureAction)

    presentViewController(actionSheetController, animated: true, completion: nil)
}

I've already "cleaned" the project and reset the simulator settings, but still not getting the prompt to get displayed.

MC.
  • 481
  • 7
  • 15
  • Possible duplicate of [App does not have access to your photos or videos iOS 9](http://stackoverflow.com/questions/32768012/app-does-not-have-access-to-your-photos-or-videos-ios-9) – bummi Jan 21 '16 at 10:11

2 Answers2

7

This happens because the CFBundleDisplayName key in your Info.plist file has an empty value and the message in the alert that prompts for permission to access the Photo Library cannot be constructed. Adding the following lines, cleaning the project and building again fixes the problem:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDisplayName</key>
    <string>$(PRODUCT_NAME)</string>
    <!-- More keys and values -->
</dict>
</plist>

Thanks to Vladimir Gorbenko for helping me solve this.

Community
  • 1
  • 1
MC.
  • 481
  • 7
  • 15
  • lifesaver - would have never figured this out on my own – Tys Jun 03 '16 at 14:06
  • It does not work on iOS 10.1 simulator. I posted an issue here. http://stackoverflow.com/questions/40386819/ios-request-permission-does-not-show/40386997#40386997 – Capella Nov 02 '16 at 18:14
1

Go to Info.plist and add Bundle Display name.Then add the code.

enter image description here

Alvin George
  • 14,148
  • 92
  • 64