"The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription" 的崩溃是什么?

What is the crash of "The app's Info.plist must contain an NSPhotoLibraryAddUsageDescription"?

我遇到了以下错误 (iOS 11):

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

请注意,尽管应用程序 info.plist 确实包含 NSPhotoLibraryUsageDescription 它仍然会崩溃,为什么?

Note that although the application info.plist does contains NSPhotoLibraryUsageDescription it still crashes, why?

我认为在比较 NSPhotoLibraryUsageDescriptionNSPhotoLibraryAddUsageDescription 时存在误解,如 Information Property List Key Reference 中所述:

NSPhotoLibraryUsageDescription:

This key lets you describe the reason your app accesses the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

这与让应用程序能够访问(获取)设备照片库有关。

NSPhotoLibraryAddUsageDescription:

This key lets you describe the reason your app seeks write-only access to the user’s photo library. When the system prompts the user to allow access, this string is displayed as part of the alert.

这与让应用能够写入(添加)照片到设备照片库有关。


显然,要解决此崩溃,您必须将 NSPhotoLibraryAddUsageDescription 添加到应用程序的 plist 文件中:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Our application needs permission to write photos...</string>

作为属性列表视图:

以上回答有误。正确的plist条目应该如下

<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) needs permission to access photos on your device</string>