微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHPhotoLibrary.requestAuthorization()不会在iOS 9上触发授权提示

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

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

我已经“清理”了项目并重置了模拟器设置,但仍未获得显示提示.

解决方法

发生这种情况是因为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帮助我解决这个问题.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐