IOS 7 UIImagePickerController Camera No Image

For some reason, the first time I open the UIImagePickerController in camera mode in my application, it becomes empty. I need to close and reopen this point of view in order to start working with the camera power. I use standard code that works great in iOS 6 to capture the camera. From the example below, I run the capturePhoto: method capturePhoto: Anyone else come across this jenkiness with an iOS 7 camera? I checked the Apple dev forums, but it's almost impossible to find the answers there.

 - (IBAction)capturePhoto:(id)sender { [self doImagePickerForType:UIImagePickerControllerSourceTypeCamera]; } - (void)doImagePickerForType:(UIImagePickerControllerSourceType)type { if (!_imagePicker) { _imagePicker = [[UIImagePickerController alloc] init]; _imagePicker.mediaTypes = @[(NSString*)kUTTypeImage]; _imagePicker.delegate = self; } _imagePicker.sourceType = type; [self presentViewController:_imagePicker animated:YES completion:nil]; } 

why so empty?

+8
ios ios7
Sep 21 '13 at 8:15
source share
4 answers

I am also using UIImagePickerController and faced the same blank screen issue. I would like to talk a little about what Cloudts said about authorizing iOS 7 for the camera.

Link: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/Reference/Reference.html

"Recording audio always requires explicit permission from the user; video recording also requires the permission of the user on devices sold in certain regions."

Here are some snippets of code that you can start to check if you have permission for the camera and request it if your application has not requested it before. If you are denied due to an earlier request, your application may need to notify the user that they enter the settings to manually allow access, as Cloudes pointed out.

IOS 7 example

 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"); } 
+16
Sep 29 '13 at 2:55
source share
β€” -

In iOS 7, an application can access the camera before getting user authorization. When the application accesses the camera for the first time, iOS displays a warning to ask the user. Users can also set authorization in Settings--Privacy--Camera--[Your app name] .

The camera will turn off if the switch is off.

  • If you call the camera using AVCaptureDeviceInput , you can check how:

     NSError *inputError = nil; AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&inputError]; if (inputError && inputError.code == AVErrorApplicationIsNotAuthorizedToUseDevice) { // not authorized } 
  • If you are calling using the UIImagePickerController , I am still looking for a way to check if it has received authorization.

    I tried these two methods:

     [UIImagePickerController isSourceTypeAvailable:] [UIImagePickerController isCameraDeviceAvailable:] 

    but they did not work, and they all returned YES.

UPDATE

Thanks for expanding Scott. [AVCaptureDevice authorizationStatusForMediaType:] is the best way to check.

 AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusAuthorized) { // successful } else { // failed, such as // AVAuthorizationStatusNotDetermined // AVAuthorizationStatusRestricted // AVAuthorizationStatusNotDetermined } 

But don't forget to check the iOS version because [AVCaptureDevice authorizationStatusForMediaType:] and AVAuthorizationStatus are available above iOS 7.

 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { // code for AVCaptureDevice auth checking } 
+7
Sep 23 '13 at 8:58
source share

I ran into the same problem and tried every solution on the internet with no luck. But finally, I found out that the background thread prevented the camera screen from showing. If you have a background thread working when you try to open the camera, like me, try blocking the background thread and see what happens. Hope you can get around this.

+4
Sep 27 '13 at 23:56 on
source share

I came across this control AQPhotoPicker . It is fairly easy to use and hopefully helps you.

0
Sep 14 '14 at 11:36 on
source share



All Articles