即使添加相机使用说明/照片库使用说明,也不会显示警报

时间:2019-01-11 01:41:50

标签: ios uiimagepickercontroller

我的应用程序中有相机/照片库,因此我在plist中添加了请求权限。但是,运行应用程序后,它甚至不会弹出警报。只需访问即可选择照片/相机。我有什么想补充的吗?

谢谢!

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:-1)

在iOS上请求媒体捕获的授权:    https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios

配置应用程序的Info.plist文件:

如果您的应用程序使用设备相机,请在应用程序的Info.plist文件中包含“ NSCameraUsageDescription”键。

验证并请求捕获授权:

   override func viewDidLoad() {
       super.viewDidLoad()
         switch AVCaptureDevice.authorizationStatus(for: .video) {
          case .authorized:  // The user has previously granted access to the camera.
              .....

          case .notDetermined: // The user has not yet been asked for camera access.
               AVCaptureDevice.requestAccess(for: .video) { granted in
                if granted {
                    .....
                }
        }

         case .denied: // The user has previously denied access.
             return
         case .restricted: // The user can't grant access due to restrictions.
           return
       }
 }