我正在使用具有 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/