iOS 12:未经相机许可就可以使用相机对话框

时间:2018-10-03 08:04:13

标签: ios objective-c

在iOS 11中,当该应用程序首次启动时,我将单击相机的按钮,然后它将显示“相机权限”对话框。

但是在iOS 12中,当我单击“相机”按钮时,无需任何许可即可直接打开相机。

我已经在Privacy - Camera Usage Description文件中添加了Info.plist

我很困惑该怎么办?请给我一些解决方案。

+(void)checkPermissionForCameraWithSuccess:(void (^) (void))successHandler  failure:(void (^) (void))failureHandler
{
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

    switch (status)
    {
        case AVAuthorizationStatusRestricted:
        case AVAuthorizationStatusDenied:{
            if (failureHandler)
                dispatch_async (dispatch_get_main_queue (), ^{ failureHandler (); });
        }; break;
        case AVAuthorizationStatusAuthorized:{
            if (successHandler)
                dispatch_async (dispatch_get_main_queue (), ^{ successHandler (); });
        }; break;
        case AVAuthorizationStatusNotDetermined:
        {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (!granted)
                {
                    if (failureHandler) {
                        dispatch_async (dispatch_get_main_queue (), ^{ failureHandler (); });
                    }
                } else {
                    if (successHandler) {
                        dispatch_async (dispatch_get_main_queue (), ^{ successHandler (); });
                    }
                }
            }];
            break;
        }
        default:
            break;
    }
}

注意:默认情况下,它将返回status = AVAuthorizationStatusAuthorized,而没有任何权限对话框。

0 个答案:

没有答案