前言
升級iOS11系統(tǒng)的手機使用我們app的拍照功能時閃退,經(jīng)過查看代碼發(fā)現(xiàn)是 writeImageToSavedPhotosAlbum
這個方法引起的
官方文檔這是這樣解釋的:
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.
這是一個iOS11版本新增的權限怔鳖,涉及保存圖片到相冊時需要添加該權限鸭津。
iOS11以前:
NSPhotoLibraryUsageDescription:訪問相冊和存儲照片到相冊(讀寫),會出現(xiàn)用戶授權英支。
iOS11之后:
NSPhotoLibraryUsageDescription:無需添加。默認開啟訪問相冊權限(讀)哮伟,無需用戶授權干花。
NSPhotoLibraryAddUsageDescription: 添加內(nèi)容到相冊(寫),會出現(xiàn)用戶授權澈吨。
解決辦法
原來是跟 iOS 10 保存圖片把敢、調(diào)用相機一樣, Info.plist 里面要涉及隱私數(shù)據(jù)時要添加一句“提示語”谅辣。于是打開 Info.plist修赞,點擊 + 號,在 Key 中輸入:Privacy - Photo Library Additions Usage Description桑阶,Type 選擇 String柏副,Value 中輸入你的提示語。再次 Build蚣录,運行割择,OK!