【问题标题】:Asking camera permission on iPad在 iPad 上询问相机权限
【发布时间】:2014-12-31 21:27:19
【问题描述】:

在一个应用中,我目前是在检查相机权限后才拍照,如下:

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(authStatus == AVAuthorizationStatusAuthorized) {
    // Take picture
}else{
    // Prompt user to go into their settings and add permissions for app
}

但是,在第一次使用时,a) 最初的“您想授予此应用摄像头权限吗?”提示未出现,并且 b) 该应用程序未出现在 iPad 的隐私设置 -> 相机下。这导致了无法在应用程序中授予相机权限的不幸情况。

任何有关如何避免这种情况的建议将不胜感激。感谢阅读。

【问题讨论】:

    标签: ios ipad camera


    【解决方案1】:

    您需要使用以下代码请求权限:

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if(authStatus == AVAuthorizationStatusAuthorized)
    {
        // Take picture
    }
    else
    {
        [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted)
        {
           if (granted)
           {
               NSLog(@"User Granted");
           }
           else
           {
               NSLog(@"User Denied");
           }
        }];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-17
      • 2023-03-07
      • 1970-01-01
      • 2011-04-03
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 2021-04-26
      相关资源
      最近更新 更多