【转载】ios11 相册读写权限 变更

http://www.jianshu.com/p/c03a87e4ca87

 

大家都知道访问相册需要申请用户权限。 相册权限需要在info.plist—Property List文件中添加NSPhotoLibraryUsageDescription键值对,描述文字不能为空。 iOS11之前:访问相册和存储照片到相册(读写权限),需要用户授权,需要添加NSPhotoLibraryUsageDescription。
iOS11之后:默认开启访问相册权限(读权限),无需用户授权,无需添加NSPhotoLibraryUsageDescription,适配iOS11之前的还是需要加的。 添加图片到相册(写权限),需要用户授权,需要添加NSPhotoLibraryAddUsageDescription

总结:iOS11之后如果需要写入权限需要添加
NSPhotoLibraryAddUsageDescription字段。  
   NSPhotoLibraryUsageDescription:
Property List:
   Privacy - Photo Library Usage Description
Source Code:
  NSPhotoLibraryUsageDescription
是否允许此APP使用相册?
   NSPhotoLibraryAddUsageDescription :
Property List:
   Privacy - Photo Library Additions Usage Description
Source Code:
   NSPhotoLibraryAddUsageDescription
是否允许此APP保存图片到相册?

苹果官方文档说明:

https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73

NSPhotoLibraryAddUsageDescription

NSPhotoLibraryAddUsageDescription (String - iOS) 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.

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

 

This key is supported in iOS 11.0 and later.

NSPhotoLibraryUsageDescription

NSPhotoLibraryUsageDescription (String - iOS) 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.

Although this keys governs read and write access to the user’s photo library, it’s best to use NSPhotoLibraryAddUsageDescription if your app needs only to add assets to the library and does not need to read any assets.

Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and that 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.

 

This key is supported in iOS 6.0 and later.

 



作者:小孩仔
链接:http://www.jianshu.com/p/c03a87e4ca87
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2017-10-20 11:34  子柱  阅读(1199)  评论(0编辑  收藏  举报