ios - Swift 手动设置相机权限

标签 ios swift camera

我正在使用具有 bool 方法调用的卡片扫描库来检查是否已设置相机权限。在 Swift 3 中有没有一种方法可以让我根据警报操作 Controller 手动设置权限。

如果已经通过库创建了图像选择器,我不想创建另一个图像选择器。

这可以做到吗?

谢谢

最佳答案

不,你不能那样做。但是当然,您可以让用户使用以下代码授予权限,然后您可以将值存储在 bool 变量中以供将来使用。

if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) ==  AVAuthorizationStatus.authorized
{
   // Already Authorized
}
else
{
   AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted :Bool) -> Void in
      if granted == true
      {
         // User Granted
      }
      else
      {
         // User Rejected
      }
   });
}

关于ios - Swift 手动设置相机权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43392757/

相关文章:

ios - HLS 流媒体 : Multiple Audio Alternatives in Video Stream

ios - 无法调用非函数类型的值 'CGFloat' - Xcode -

swift - CoreData 在用户数量较少时崩溃

ios - 为什么在 swift 项目中需要 Objective-C 桥接头?

ios - 如何在此 Segue 中添加基本 URL 和其他参数

ios - "No iOS Distribution certificate was found"

iphone - 如何从委托(delegate)访问 UITableView?

ios - 在相机应用程序中单击使用按钮保存照片

swift - 慢人脸检测 Firebase MLKit

c# - ASP.Net 实时流式传输 IP 摄像机视频和音频