Info.plist must contain an NSCameraUsageDescription key

Posted in :

預設的 code 在 iOS 10 裡使用相機會出錯,錯誤訊息:

The app’s Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

發現直接修改 Info.plist 無效,需要 在 App Info tab 裡按右鍵選 add row 去增加才行:

 

取用 photo library 和 取用 camera 需要分列加 2次。

以 Privacy 開頭的都是。Xcode 把所有需徵求使用者同意,需設定 usage description 的都陳列在選單裡。

swift 取用 photo library sample code:

let imagePicker = UIImagePickerController()
imagePicker.sourceType = .photoLibrary
self.present(imagePicker, animated: true, completion: nil)

拍照用 sample code:

        //建立一個ImagePickerController
        let imagePicker = UIImagePickerController()

        // 設定影像來源 這裡設定為相簿
        imagePicker.sourceType = .camera

        // 設置 delegate
        imagePicker.delegate = self
        imagePicker.allowsEditing = true
        self.present(imagePicker, animated: true, completion: nil)

 

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *