简体   繁体   English

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

[英]PHPhotoLibrary.requestAuthorization() not triggering authorization prompt on iOS 9

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

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. 发生这种情况是因为Info.plist文件中的CFBundleDisplayName键具有空值,并且无法构建警报中提示访问照片库的权限的消息。 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. 感谢Vladimir Gorbenko帮助我解决这个问题。

Go to Info.plist and add Bundle Display name.Then add the code. 转到Info.plist并添加Bundle Display name。然后添加代码。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ios 14 PHPhotoLibrary.requestAuthorization 不调用处理程序 - ios 14 PHPhotoLibrary.requestAuthorization not calling handler “PHPhotoLibrary.requestAuthorization”未在iOS 9中询问权限 - “PHPhotoLibrary.requestAuthorization” not asking permissions in iOS 9 Xcode 8和Swift 3-PHPhotoLibrary.requestAuthorization崩溃 - xcode 8 & swift 3 - PHPhotoLibrary.requestAuthorization crashing 通过UNUserNotificationCenter.current()。requestAuthorization请求iOS10通知授权时,bundleIdentifier!= nil - bundleIdentifier != nil when requesting iOS10 notification authorization via UNUserNotificationCenter.current().requestAuthorization iOS PHPhotoLibrary performChanges标题本地化 - iOS PHPhotoLibrary performChanges title localization UNUserNotificationCenter.current().requestAuthorization 可能不提示的一些可能原因是什么? - What are some possible reasons that UNUserNotificationCenter.current().requestAuthorization might not prompt? HealthKit requestAuthorization返回代码100:“授权会话超时” - HealthKit requestAuthorization returns code 100: “Authorization session timed out” 如何在ioS中从PHPhotoLibrary获取引用URL? - How to get ref url from PHPhotoLibrary in ioS? iOS:如何将iPhone设置链接到PHPhotoLibrary权限 - iOS: how to link iPhone settings to PHPhotoLibrary permission iOS:使用设置切换PHPhotoLibrary权限 - iOS: Switch PHPhotoLibrary permissions using settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM