iOS 8之后相机授权判断

2016-08-19  本文已影响9人  走道牙的人

参考http://blog.sina.com.cn/s/blog_b1540f630102w6zn.html

示例代码

// 判断相机授权
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"没有相机权限" message:@"请去设置-隐私-相机中对52度授权" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"现在就去" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"以后再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self cancle];
    }];
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
    return;
}
上一篇下一篇

猜你喜欢

热点阅读