我也在使用 UIImagePickerController 并在空白屏幕上遇到了同样的问题。我想稍微扩展一下 klaudz 提到的有关 iOS 7 相机授权的内容。
参考:
https ://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html
“录制音频总是需要用户的明确许可;录制视频还需要用户对某些地区销售的设备的许可。”
下面是一些代码片段,您可以从这些代码片段开始检查您是否拥有摄像头权限,如果您的应用之前没有请求过,请请求它。如果您由于较早的请求而被拒绝,您的应用程序可能需要向用户发出通知以进入设置以手动启用访问权限,正如 klaudz 指出的那样。
iOS 7 示例
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");
}
// 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) {
// Make sure we execute our code on the main thread so we can update the UI immediately.
//
// See documentation for ABAddressBookRequestAccessWithCompletion where it says
// "The completion handler is called on an arbitrary queue."
//
// Though there is no similar mention for requestAccessForMediaType, it appears it does
// the same thing.
//
dispatch_async(dispatch_get_main_queue(), ^{
if(granted){
// UI updates as needed
NSLog(@"Granted access to %@", mediaType);
}
else {
// UI updates as needed
NSLog(@"Not granted access to %@", mediaType);
}
});
}];
}
else {
NSLog(@"Unknown authorization status");
}