iOS7权限检查

__block BOOL isAvalible = NO;
    NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio
   
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
   
    // This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
    if(authStatus == AVAuthorizationStatusRestricted){
        NSLog(@"Restricted");
    }
   
    // The user has explicitly denied permission for media capture.
    else if(authStatus == AVAuthorizationStatusDenied){
        NSLog(@"Denied");
       
    }
   
    // The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
    else if(authStatus == AVAuthorizationStatusAuthorized){
        NSLog(@"Authorized");
        isAvalible = YES;
    }
   
    // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
    else if(authStatus == AVAuthorizationStatusNotDetermined){
       
        [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
            if(granted){
                NSLog(@"Granted access to %@", mediaType);
            }
            else {
                NSLog(@"Not granted access to %@", mediaType);
            }
        }];
       
    }
   
    else {
        NSLog(@"Unknown authorization status");
    }
  

最终判断 isAvalible 即可

http://www.cocoachina.com/ask/questions/show/100962

我的回答,有兴趣可以看下。

你可能感兴趣的:(ios7,相机,权限检查,麦克风)