是否可以同时请求相机许可和照片库许可?

问题描述 投票:0回答:1

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

ios swift permissions uiimagepickercontroller access-control
1个回答
0
投票

每个rmaddy的限定评论,您不能同时要求两者。尽管如此,我还是想分享我如何呈现两个请求back-to-back,这与我们获得的效果差不多。

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

            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.