有没有办法同时请求相机权限和照片库权限?



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

根据 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
}
}
}
}

最新更新