崩溃请求授权iOS 10中的照片库 [英] Crash requesting authorisation to Photos Library in iOS 10

查看:231
本文介绍了崩溃请求授权iOS 10中的照片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个示例iOS 10应用程序请求授权照片库并在真实设备上崩溃,并出现以下崩溃错误:

I have a sample iOS 10 application requesting authorisation to the Photos Library and crashing on a real device with the following crash error:

PhotosAuthorizationCrashTest [2014:42551] [access]< private>

可以找到回购这里

这是请求授权的代码(Swift 3.0):

Here's the code that requests authorisation (Swift 3.0):

private func requestAuthorizationIfNeeded() {
    DispatchQueue.main.async {
        let status = PHPhotoLibrary.authorizationStatus()
        if status == .authorized {
            return
        }

        PHPhotoLibrary.requestAuthorization({ (status) in
            if status == .authorized {
                return
            }

            NSLog("Could not get authorization to access photos")
        })
    }
}


推荐答案

我发现这个问题与一些使用说明密钥在iOS 10中已成为强制性的事实有关。

I've found the issue to be related with the fact that some Usage Description keys have become mandatory in iOS 10.

尽管 NSPhotoLibraryUsageDescription 自iOS 6以来一直存在,但它只是iOS 10中的一项要求,并且崩溃消息不是很有帮助。

Even though NSPhotoLibraryUsageDescription has been around since iOS 6, it has only become a requirement in iOS 10, and the crash message wasn't very helpful.

在最新的Xcode(此时为Xcode 8 beta 3)的模拟器中,崩溃消息更加详细(即使在设备上它仍然是相同的):

In the simulator of the latest Xcode (Xcode 8 beta 3 at the moment) the crash message is a bit more detailed, (even though on a device it is still the same):


[access]此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据。应用程序的Info.plist必须包含一个NSPhotoLibraryUsageDescription键,其中包含一个字符串值,向用户解释应用程序如何使用此数据。

[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

所以添加 NSPhotoLibraryUsageDescription 到我的 Info.plist 文件修复了此问题。

So adding NSPhotoLibraryUsageDescription to my Info.plist file has fixed the issue.

有关更多文档,请参阅 Cocoa Keys

For more documentation, see Cocoa Keys

更具体地说,名为的部分NSPhotoLibraryUsageDescription


重要提示:为了保护用户隐私,iOS 10.0上或之后链接的iOS应用程序必须静态声明这样做的意图才能访问用户的照片库。在应用的Info.plist文件中包含NSPhotoLibraryUsageDescription键,并为此密钥提供目的字符串。如果您的应用尝试访问用户的照片库而没有相应的用途字符串,则您的应用会退出。

Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s photo library, must statically declare the intent to do so. Include the NSPhotoLibraryUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits.

这篇关于崩溃请求授权iOS 10中的照片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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