PHPhotoLibrary.requestAuthorization()在iOS 9上没有触发授权提示 [英] PHPhotoLibrary.requestAuthorization() not triggering authorization prompt on iOS 9

查看:345
本文介绍了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照片,样式:.Default){
(action)in
PHPhotoLibrary.request授权({(status:PHAuthorizationStatus)in
开关状态{
case .Authorized:
dispatch_async(dispatch_get_main_queue(),{
print(Authorized)
})
break
case .Denied:
dispatch_async(dispatch_get_main_queue $ b print(Denied)
})
break
default:
dispatch_async(dispatch_get_main_queue(),{
print(Default)
})
break
}
})
}
actionSheetController.addAction(choosePictureAction)

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


$ b $ p我已经清理了项目并重置了模拟器

这是因为 CFBundleDisplayName code>键具有空值,并且不能构造警报中提示访问照片库的权限的消息。添加以下行,清除项目并再次构建修复了此问题:

 <?xml version =1.0encoding = UTF-8?> 
<!DOCTYPE plist PUBLIC - // Apple // DTD PLIST 1.0 // ENhttp://www.apple.com/DTDs/PropertyList-1.0.dtd\">
< plist version =1.0>
< dict>
< key> CFBundleDisplayName< / key>
< string> $(PRODUCT_NAME)< / string>
<! - 更多键和值 - >
< / dict>
< / plist>

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


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:

@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.

解决方案

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.

这篇关于PHPhotoLibrary.requestAuthorization()在iOS 9上没有触发授权提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆