即使我添加相机使用说明/照片库使用说明也没有显示警报

Not showing alert even when I add Camera Usage Description / Photo Library Usage Description

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

谢谢!

在 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
       }
 }