UIActivityViewController 的 NSPhotoLibraryAddUsageDescription 閃退問題
Published in
3 min readMar 14, 2020
利用 UIActivityViewController 我們可以方便地將 App 裡的圖文分享到 FB & LINE,但是如果想將圖片存到手機相簿,點選 Save Image,卻可能造成 App 閃退,出現以下錯誤訊息。
2020-03-14 23:03:39.932303+0800 Demo[18921:1029072] [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 NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.
我們必須徵求使用者同意後,才能將照片存到他的手機相簿。因此請在 App 的 Info 頁面設定 NSPhotoLibraryAddUsageDescription,讓使用者同意 App 將照片存到相簿。
- 切換到 App 的 Info 頁面,點選 + 新增資料。
- 選擇 Privacy — Photo Library Additions Usage Description。
- 輸入請求文字。
Yes ! 當我們第一次點選 UIActivityViewController 的 Save Image 時,App 將顯示請求權限的文字訊息。一旦使用者同意,我們即可順利地將照片存入手機相簿裡。