【问题标题】:PHPhotoLibrary.requestAuthorization() not triggering authorization prompt on iOS 9PHPhotoLibrary.requestAuthorization() 不会在 iOS 9 上触发授权提示
【发布时间】:2015-09-29 01:23:38
【问题描述】:

我有以下功能,它显示具有两个不同选项的操作表。目前,唯一实现的选项是标题为“照片”。正确显示操作表并调用正确的操作。我的问题是在模拟器和实际设备上,我无法显示请求访问照片库的提示。

PHPhotoLibrary.authorizationStatus() 返回.Denied 并显示通知当前应用程序无权访问照片的模式:

@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)
}

我已经“清理”了项目并重置了模拟器设置,但仍然没有得到显示的提示。

【问题讨论】:

标签: ios swift cocoa-touch


【解决方案1】:

发生这种情况是因为您的 Info.plist 文件中的 CFBundleDisplayName 键的值是空的,并且无法构造警报中提示您获得照片库访问权限的消息。添加以下行,清理项目并再次构建可以解决问题:

<?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>

感谢Vladimir Gorbenko 帮助我解决这个问题。

【讨论】:

【解决方案2】:

转到 Info.plist 并添加 Bundle Display name。然后添加代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-15
    • 2016-07-07
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 2016-06-22
    相关资源
    最近更新 更多