【问题标题】:Is there a way to request both camera permission and photo library permission at the same time?有没有办法同时请求相机权限和照片库权限?
【发布时间】:2020-02-17 02:40:31
【问题描述】:

我正在创建一个应用程序,让用户可以选择上传个人资料图片。我使用Fusuma 作为UIImagePickerController 的第三方替代品。它有一个错误,要求我呈现图像拾取视图控制器 (FusumaViewController) 之前请求相机和照片库权限。我可以通过PHPhotoLibrary.requestAuthorization { (status) in } 请求照片库权限,但是当图像拾取视图控制器出现时,它会要求访问相机。我想请求同时访问相机和照片库,这可能吗?

【问题讨论】:

  • 不,不可能。
  • 非常感谢@rmaddy 的及时回复

标签: ios swift permissions uiimagepickercontroller access-control


【解决方案1】:

根据 rmaddy 的合格评论,您不能同时请求两者。不过,我想我会分享我是如何背靠背呈现这两个请求的,这几乎是我们所能得到的。

import UIKit
import Photos

class SomeViewController: UIViewController {

    ...

    @IBAction func requestAccessButtonPressed(_ sender: Any) {
        PHPhotoLibrary.requestAuthorization { (status) in

            //Use PHAuthorizationStatus as you need here

            AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in 

                //Use the boolean "response", which tells us whether the user granted photo access here

            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 2019-09-22
    • 2021-04-11
    • 2019-04-17
    • 2020-07-31
    相关资源
    最近更新 更多