国行iPhone在iOS7下获取摄像头需要进行认证,或者手动在iPhone的“设置”里对你的App开启摄像头。
在你不知道你的App是否能打开摄像头的之前,你可以根据API获取摄像头状态:
typedef enum : NSInteger { AVAuthorizationStatusNotDetermined = 0, AVAuthorizationStatusRestricted, AVAuthorizationStatusDenied, AVAuthorizationStatusAuthorized } AVAuthorizationStatus;
// Check camera status AVAuthorizationStatus cameraStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (cameraStatus == AVAuthorizationStatusDenied) { NSLog(@"Denied(被拒绝了,不能打开)"); } else if (cameraStatus == AVAuthorizationStatusAuthorized) { NSLog(@"Authorized(已经获得了许可)"); } else if (cameraStatus == AVAuthorizationStatusNotDetermined) { NSLog(@"Not Determined(不确定是否获得了许可)"); } else if (cameraStatus == AVAuthorizationStatusRestricted) { NSLog(@"Restricted(受限制:已经询问过是否获得许可但被拒绝)"); }
祝您愉快开心 ^_^