In my app, i use a UIActionSheet and UIImagePickerController. Action Sheet opens optiones (as choose photo, choose video) and Image Picker Controller opens library. This system works good for iPhone device testing but for iPad, Action Sheet works fine while Picker Controller does not.
I have set required permissions for iOS10, for camera and photo library. This cannot be the problem.
My code for selecting photo:
- (void)selectPhoto {
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
Required delegate methods were written either. And as I mentioned, everyting works as it should do in iPhones.
When I try to open photo library first I get this warning messages:
[Warning] <_UIPopoverBackgroundVisualEffectView 0x147c5ad0> is being
asked to animate its opacity. This will cause the effect to appear
broken until opacity returns to 1.
Nothing is broken, app is still running (not freezing). However if I try to open photo library, this time I get:
Warning: Attempt to present on
which is already presenting (null)
Then, the problem might be popover problem but I could not find the answer.
Thank you!
Edit: My action sheet delegate method:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
switch (buttonIndex) {
case 0:
[self selectPhoto];
break;
case 1:
[self selectVideo];
break;
default:
break;
}
}
Edit 2: I found that:
On iPad, you must present the browser interface using a popover as
described in initWithContentViewController: and Presenting and
Dismissing the Popover in UIPopoverController Class Reference. If, on
iPad, you attempt to present the browser interface modally
(full-screen), the system raises an exception.
UIPopoverController is now deprecated. Thus I should use another way. If anyone can help me about this, I'd be ver happy.
For iPad use the code to open the UIImagePicker
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:picker animated:NO completion:nil];
}];
There is a list of all Cocoa Keys that you can specify in your Info.plist file:
https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
iOS already required permissions to access microphone, camera, and media library earlier (iOS6, iOS7), but since iOS10 the apps will crash if you don't provide the description why you are asking for the permission.
On iPad you can't show UIImagePickerController popover over an already onscreen UIActionSheet popover.
Replace
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
with
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
and it must work.
And remove [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];, as soon as you click on a button, UIActionSheet is dismissed automatically.
To show an image picker on both the iPhone and iPad, you need to present it as a popover.
So the implementation to show your picker would change to
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
self.imagePickerController.modalPresentationStyle = UIModalPresentationPopover; //This is needed
self.imagePickerController.sourceView = self.view; //This is needed
[self presentViewController:self.imagePickerController animated:YES completion:nil];
Do make sure your action sheet is dismissed before you present the picker.
Related
My app is structured with a central view controller that adds 3 to 4 subviews to the main view. In one of the added view controllers I present a camera to the user. When I dismiss the image picker, every subview except the one in which I present the camera (the view controller) disappears. I think it might be related to how the app is structured and the view stack. The app works fine when running iOS 8 on an iPhone and iOS 7 on an iPad. I am having this issue only when I am running iOS 8 on the iPad. I made sure the code followed the apple documentation on how to present and dismiss the image picker. Here is the code used to present the image picker.
-(IBAction)photoButtonPressed:(id)sender
{
// Prompt for camera or photo library
// Retrieve image and set it as this button's default image
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage, nil];
imagePicker.allowsEditing = NO;
imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; //play around with this
[self presentViewController:imagePicker animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Camera not found" message:#"There is no camera available on this device." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
Code used to dismiss
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
CGSize scaleSize = CGSizeMake(1024.0f, 1280.0f);
UIImage *capturedImage;
// Handle a still image capture
capturedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
if (capturedImage) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
photoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
photoEntity = nil;
[self.takePhotoButton setImage:[UIImage imageWithData:photoData ] forState:UIControlStateNormal];
if ([self isAnyButtonSelected] || ![_answerTextField.text isEqualToString:#""] || !_questionBoolean.hidden) {
[Tools enableControl:_saveButton];
}
} else {
newPhotoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
photoEntity = nil;
}
}
}
And here I tried messing with the parent views and controllers in this method. I was able to get the app to return to the central view controller minus the current view controller that is in charge of taking the photos. The only problem is that the app's touch is now disabled and I am missing one view.
- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
{
// [self willMoveToParentViewController:nil];
// [picker.view removeFromSuperview];
// [picker removeFromParentViewController];
[self dismissViewControllerAnimated:YES completion:nil];
}
I was going to post photos but I am currently unable to because I am new to stack overflow. Any help would be appreciated. Thanks!
Ok so the app is not using story boards but it is using xib files. It is inherited code and the app was created several years ago. There are multiple view controllers with multiple views. There is a central view controller where all the other view controllers are added to the central view.
[self.view addSubview:_catViewController.tableView];
[self.view addSubview:_listViewController.tableView];
[self.view addSubview:_queryViewController.view];
[self.view bringSubviewToFront:_queryViewController.view];
queryViewController is where I am taking the photo. When I dismiss every view is gone except the query view controller which happens to take up the entire screen (it previously did not). Let me know if I need to add more information! Thanks
So, the general problem is that your central view controller is adding the views of other view controllers to itself. You can't do that -- it breaks view controller encapsulation. And when you violate encapsulation, stuff just breaks. (That's a vague statement, but 100% true :-p) Unfortunately, you either need to stab in the dark to find a hack to make it work, or repartition the problem to respect encapsulation. The latter is probably better if you'll need to maintain this code in the future.
hoping for some insight. I have an issue with my Xcode app when I run it in simulator iPhone 6 iOS 8 or on my iPhone 4s iOS 8.0.2. The issue is that when I click on my photo tab to access CameraViewController the image picker code works fine in both situations (photo library for simulator and camera for iPhone)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
_imagePicker = [[UIImagePickerController alloc]init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
Then when I click on a photo in simulator or take a photo with my iPhone and click on use photo the chosen image and fields that are there to be edited appears for a split second and then it goes back to image picker view to pick another photo (just keeps looping around like that.
here is my code for imagepickercontroller:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.chosenImageView.image = chosenImage;
[self dismissViewControllerAnimated:YES completion:nil];
}
Possible additional info in case you need it:
my Xcode is 6.0.1
my Base SDK is Latest iOS (iOS 8.0)
my Deployment Target 7.1
I did not alter any of these other than updating my when notified
any insight to fix this issue will be much appreciated
Grazie
The only problem I can see is that you are presenting the UIImagePickerContoller at ViewWillAppear or I can say you are performing the task of picking an image at ViewWillAppear.
ViewWillAppear gets called every time the ViewController will become active. This is leading your app in the loop of picking the image since the ViewWillAppear will be called again when the UIImagePickerController will be dismissed when didFinishPickingMediaWithInfo is called. Place a BREAK POINT at ViewWillAppear to check it yourself.
Try to move your code somewhere else other than ViewWillAppear.
You can place a button or something like that and write the same code in its -IBAction, that you have written in ViewWillAppear.
In iOS 8 I am having problem capturing images from camera till now I am using this code for
UIImagePickerController *controller=[[UIImagePickerController alloc] init];
controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
controller.delegate=(id)self;
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];
But in iOS 8 I am getting this:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
I have tried with the solution provided by This Post with
#property (strong,nonatomic)UIImagePickerController *controller;
_controller=[[UIImagePickerController alloc] init];
_controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
_controller.delegate=(id)self;
_controller.sourceType=UIImagePickerControllerSourceTypeCamera;
_[self presentViewController:controller animated:YES completion:nil];
and this
...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...
and this
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self presentViewController:controller animated:YES completion:nil];
});
and this
[self presentViewController:controller animated:YES completion:NULL];
and this
[self presentViewController:controller animated:YES completion:^{
}];
any idea?
I'm pretty sure this is just a bug in iOS 8.0. It's reproducible with the simplest of POC apps that does nothing more than attempt to present a UIImagePickerController like you're doing above. Furthermore, there's no alternative pattern to displaying the image picker/camera, to my knowledge. You can even download Apple's Using UIImagePickerController sample app, run it, and it will generate the same error out of the box.
That said, the functionality still works for me. Other than the warning/error, do you have issues with the functioning of your app?
I was struggling with this issue for several hours, i have read every relevant topic and found out that the error was caused because under the privacy settings of my device, the camera access to my app was blocked!!! I have never denied access to camera and i don't know how it was blocked but that was the problem!
I don't have enough reputation points to comment on #greg's answer above, so will add my observations here. I have a Swift project for both iPad and iPhone. I have a method inside my main view controller (relevant bit below). When I test this on a phone, everything works properly and no warnings are generated. When I run it on an iPad, everything works properly but I see the warning about snapshotting the view. The interesting bit, however, is that when I run on an iPad without using the popover controller, everything works properly with no warning. Unfortunately, Apple mandates that the image picker must be used within a popover on iPad, if the camera is not being used.
dispatch_async(dispatch_get_main_queue(), {
let imagePicker: UIImagePickerController = UIImagePickerController();
imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
imagePicker.mediaTypes = [kUTTypeImage];
imagePicker.allowsEditing = false;
imagePicker.delegate = self;
if(UIDevice.currentDevice().userInterfaceIdiom == .Pad){ // on a tablet, the image picker is supposed to be in a popover
let popRect: CGRect = buttonRect;
let popover: UIPopoverController = UIPopoverController(contentViewController: imagePicker);
popover.presentPopoverFromRect(popRect, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Up, animated: true);
}else{
self.presentViewController(imagePicker, animated: true, completion: nil);
}
});
I ran into this after calling UIImagePickerController presentViewController: from the callback to a UIAlertView delegate. I solved the issue by pushing the presentViewController: call off the current execution trace using dispatch_async.
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
dispatch_async(dispatch_get_main_queue(), ^{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if (buttonIndex == 1)
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController: imagePickerController
animated: YES
completion: nil];
});
}
I had this issue when animating some views and the app would go into background mode and come back. I handled it by setting a flag isActive. I set it to NO in
- (void)applicationWillResignActive:(UIApplication *)application
and YES in
- (void)applicationDidBecomeActive:(UIApplication *)application
and animate or not animate my views accordingly. Took care of the issue.
I had this with an UIAlertControllerStyleActionSheet giving the user the option to take a photo with the camera or use one from library.
I tried a symbolic breakpoint on the error message
That showed me the error is produced by the intern use of a UICollectionView during presentation
[self presentViewController:alert animated:YES completion:nil];
I fixed this by explixitly setting the frame before presenting
[alert setPreferredContentSize: alert.view.frame.size];
Here is the complete methode that is working without the error
-(void)showImageSourceAlertFromSender:(id)sender{
UIButton *senderButton = (UIButton*)sender;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:#"Camera" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self takePhoto];
}];
UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:#"Library" style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self selectPhotoFromLibraryFromSender:sender];
}];
[alert addAction:cameraAction];
[alert addAction:libraryAction];
alert.popoverPresentationController.delegate = self;
alert.popoverPresentationController.sourceRect = senderButton.frame;
alert.popoverPresentationController.sourceView = self.view;
[alert setPreferredContentSize: alert.view.frame.size];
[self presentViewController:alert animated:YES completion:^(){
}];}
You can silence the "Snapshotting a view" warning by referencing the view property before presenting the view controller. Doing so causes the view to load and allows iOS render it before taking the snapshot.
UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.popoverPresentationController.barButtonItem = (UIBarButtonItem *)sender;
... setup the UIAlertController ...
[controller view]; // <--- Add to silence the warning.
[self presentViewController:controller animated:YES completion:nil];
For anyone that is seeing an issue with a black preview after image capture, hiding the status bar after the UIPickerController is shown seems to fix the issue.
UIImagePickerControllerSourceType source = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
cameraController.delegate = self;
cameraController.sourceType = source;
cameraController.allowsEditing = YES;
[self presentViewController:cameraController animated:YES completion:^{
//iOS 8 bug. the status bar will sometimes not be hidden after the camera is displayed, which causes the preview after an image is captured to be black
if (source == UIImagePickerControllerSourceTypeCamera) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
}];
I found the same issue and tried everything. I have two different apps, one in objective-C and one in swift - both have the same problem. The error message comes in the debugger and the screen goes black after the first photo. This only happens in iOS >= 8.0, obviously it is a bug.
I found a difficult workaround. Shut off the camera controls with imagePicker.showsCameraControls = false and create your own overlayView that has the missing buttons. There are various tutorials around how to do this.
The strange error message stays, but at least the screen doesn't go black and you have a working app.
This might be a bug of built-in ImagePickerController. My code is working, but occasionally crashes on iPhone 6 Plus.
I've tried all solutions suggested by other answers but there were no luck. Problem finally solved after switching to JPSImagePickerController.
I've tried everything, my problem was that the image picker for the camera and photo library disappeared right after they showed. I solved it with the following line (swift)
imagePicker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
I'm pretty sure this is just a bug in iOS 8.0. It's reproducible with the simplest of POC apps that does nothing more than attempt to present a UIImagePickerController like you're doing above. Furthermore, there's no alternative pattern to displaying the image picker/camera, to my knowledge. You can even download Apple's Using UIImagePickerController sample app, run it, and it will generate the same error out of the box.
That said, the functionality still works for me. Other than the warning/error, do you have issues with the functioning of your app?
If we are using the UIImagePickerController as a property, then this warning will disappear. xcode assume that we are not using the result from the UIImagePickerController , if we are instantiating the UIImagePickerController within a function.
Calling this method worked for me. Place it after presenting your view.
[yourViewBeingPresented.view layoutIfNeeded];
I also encounter the same problem and I resolved it by checking if the camera is available:
BOOL cameraAvailableFlag = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (cameraAvailableFlag)
[self performSelector:#selector(showcamera) withObject:nil afterDelay:0.3];
I have came across with this issue. When we call the camera and release the views produced this issue. For an example call an camera and set view nil in viewDidDisappear method this error will come since there is not callback for camera event. Make sure about this case too for this error.
I got the same bug,getting bellow message in console while opening camera.
'Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.'
For me problem was with the Bundle display name in Info.plist file.it was empty some how,i put my app name there and now it working fine.i did't received any camera permission alert because of empty Bundle display name.it blocked the view from rendering.
the problem was't with view but by presenting it without a permission.you can check it on settings-->privacy-->Camera,if your app not listed there problem might be same.
I'm using Phonegap, but this thread keeps coming as the first one when Googling about the error message.
For me this issue went away by defining the imagetype to PNG.
encodingType : Camera.EncodingType.PNG
So the whole line being:
navigator.camera.getPicture(successFunction, failFunction, { encodingType : Camera.EncodingType.PNG, correctOrientation:true, sourceType : Camera.PictureSourceType .PHOTOLIBRARY, quality: 70, allowEdit : false , destinationType: Camera.DestinationType.DATA_URL});
Your mileage may vary, but that did the trick for me.
Alternatively, consider using drawViewHierarchyInRect:
Swift:
extension UIImage{
class func renderUIViewToImage(viewToBeRendered: UIView) -> UIImage
{
UIGraphicsBeginImageContextWithOptions(viewToBeRendered.bounds.size, true, 0.0)
viewToBeRendered.drawViewHierarchyInRect(viewToBeRendered.bounds, afterScreenUpdates: true)
viewToBeRendered.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return finalImage
}
}
Objective-C:
- (UIImage *)snapshot:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Also see:
https://developer.apple.com/library/ios/qa/qa1817/_index.html
How to capture UIView to UIImage without loss of quality on retina display
In my case ( XCode 7 and iOS 9 ), I use UINavigationController "hidden", so Ihave to add UINavigationControllerDelegate to present camera or roll and it work like it is supposed to! And pickerControllerDelegate.self doesn't display error either!
I am getting this error only in iOS 7 and the application crashed.
In iOS 6, I never get any error, just once of memory warning when opening the camera.
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
Here is what I am doing.
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];
[self presentModalViewController:imagePicker animated:YES];
I did tried to delay the presentModalViewController, but I am still getting the same message. After few seconds (7-10), the application crashed.
This error is only present in iOS 7.
Anybody has the clue?
The problem in iOS7 has to do with transitions. It seems that if a previous transition didn't complete and you launch a new one, iOS7 messes the views, where iOS6 seems to manage it correctly.
You should initialize your Camera in your UIViewController, only after the view has Loaded and with a timeout:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
//show camera...
if (!hasLoadedCamera)
[self performSelector:#selector(showcamera) withObject:nil afterDelay:0.3];
}
and here is the initialization code
- (void)showcamera {
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setAllowsEditing:YES];
[self presentModalViewController:imagePicker animated:YES];
}
This error also showed up for me with Apple's PhotoPicker sample code project.
I was using Xcode Version 5.0 and iOS 7.0.3 on an iPhone 4.
Steps to Reproduce:
Download Apple's PhotoPicker sample project at
https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html
In APLViewController.m comment out line 125
//imagePickerController.showsCameraControls = NO;
In APLViewController.m comment out lines 130-133
//[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
// self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
// imagePickerController.cameraOverlayView = self.overlayView;
// self.overlayView = nil;
Build and launch the app.
Once launched, rotate device to Landscape mode.
Click Camera icon to open UIImagePickerController in Camera mode.
View the console output.
Console output
PhotoPicker[240:60b] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
showsCameraControls property
The problem occurs for me when this has a value of YES (the default).
Setting this to NO eliminated the message.
Bug report
I just filed a bug report with Apple.
I've tried many of the suggestions that have been made in different posts, but have not found a satisfactory workaround.
I got the problem when I tried to present the camera view inside of a popover. Under iOS6 this was no problem but in iOS7 I got the message
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
as well.
However after I changed the presentation of the camera view to fullscreen as described in Taking Pictures and Movies, iOS Developer Library everything went fine again and the message never appeared again. However I had to make sure that depending on in which mode the app is (i.e., presenting camera view or photo roll) I had to either dismiss the popover or the view controller whenever the method - (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker was called.
create a property
#property (nonatomic) UIImagePickerController *imagePickerController;
Then
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.allowsEditing = YES;
self.imagePickerController = picker;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
This should solve the problem
I used this code to workaround the problem:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[imagePicker setShowsCameraControls:NO];
[self presentViewController:imagePicker animated:YES completion:^{
[imagePicker setShowsCameraControls:YES];
}];
} else {
[imagePicker setShowsCameraControls:YES];
[self presentModalViewController:imagePicker animated:YES];
}
I have the same issue and found a solve. I think, that error related with orientation of your application. My application uses only landscape mode, but UIImagePickerController use portrait mode. I add try-catch block to main.m, and get real exception:
Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
How i solve this problem:
1) Recheck device orientation in Target->General, or .plist file: Supported interface orientations : Landscape left, Landscape right.
2) Add in AppDelegate.m:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskLandscape | UIInterfaceOrientationMaskPortrait;
}
After this step UIImagePickerController works properly, but my viewcontrollers can be rotated to portrait mode. So, to solve this:
3) Create a category for UINavigationController, (supportedInterfaceOrientations moved from UIViewController to UINavigationController in iOS6):
#implementation UINavigationController (RotationIOS6)
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
#end
This solution works properly on iOS 6.0, 6.1, 7.0. Hope this helps.
I get this error when building app with iOS SDK 6.1, deployment target iOS 6.1 and running app on iOS 7 powered iPhone. App doesn't crash but implementing UIViewController shouldAutorotate method helps me to remove error message.
- (BOOL)shouldAutorotate {
return YES;
}
I had the same issue when I was trying to modify the demo app that come with the Avirary SDK,
in the demo app, it can only edit the photo picked from the camera roll. To try to edit the photo by capturing from camera, I first added the following code in the UIViewcontroller.m file:
#pragma mark - Take Picture from Camera
- (void)showCamera
{
//[self launchPhotoEditorWithImage:sampleImage highResolutionImage:nil];
if ([self hasValidAPIKey]) {
UIImagePickerController * imagePicker = [UIImagePickerController new];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[imagePicker setAllowsEditing:YES]; //important, must have
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:imagePicker animated:YES completion:nil];
}else{
[self presentViewControllerInPopover:imagePicker];
}
}
}
Then when I run the app, the error occurred:
Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.
To solve the error, modified the UIImagePicker delegate in your UIViewContooler.m file as shown below:
#pragma mark - UIImagePicker Delegate
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL * assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
void(^completion)(void) = ^(void){
[[self assetLibrary] assetForURL:assetURL resultBlock:^(ALAsset *asset) {
if (asset){
[self launchEditorWithAsset:asset];
}
} failureBlock:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:#"Error" message:#"Please enable access to your device's photos." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] show];
}];
UIImage * editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
if(editedImage){
[self launchPhotoEditorWithImage:editedImage highResolutionImage:editedImage];
}
};
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self dismissViewControllerAnimated:YES completion:completion];
}else{
[self dismissPopoverWithCompletion:completion];
}
}
Then the error disappeared and the app works!
Try this, use
[self performSelector:#selector(presentCameraView) withObject:nil afterDelay:1.0f];
and function
-(void)presentCameraView{
[self presentViewController:imagePicker animated:YES completion:nil];
}
to replace. [self presentModalViewController:imagePicker animated:YES];
and of cause make imagePicker as a global variable.
This is what fixed it for me on my app, ymmv
first off it is a iPhone - iPad app
in appname-Info.plist. in the Supported interface orientations(iPad) showed 4 orientations.
in the Supported interface orientations showed 3 orientations. I added the fourth and ran the app, no debug output.
Hope this helps.
I've just encountered the same issue. In my case the problem was that I had some non-ARC code and I've migrated it to ARC. When I did the migration, I didn't hold a strong reference to the UIImagePickerController and that was the reason for the crash.
Hope it helps :)
I had same issue in iOS 8, But the Camera Access was Disable inside Settings--> Privacy for my App. Just Enabled it, and It was working.
I spent long time try to find the solution, and surprisingly I have found it at the end and it was just very funny once I discovered it.
Here is what you will do to retrieve the image you picked and resume working :)
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImage* pickedImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
[composeImageView setImage:pickedImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}
Yes, to solve the issue, you only need to dismiss the picker normally as it seems this message: "Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates." stops the picker from being responsive but you can dismiss it and retrieve the image normally.
In my case it was related with a layout change: the VC presenting the UIImagePickerViewController has the status bar hidden, but the UIImagePickerViewController hasn't.
So, I solved it hiding the status bar in the UIImagePickerViewController as it's shown in this answer.
Not directly answering your question but you mentioned you had a memory warning ,you might be storing the raw image in a property which can lead to a memory warning. This is because the raw image takes up roughly 30MB of memory. I noticed a similar memory warning when testing apps on iOS6 which were on the iPhone 4 series. I still got this warning when the devices were upgraded to iOS7. There is no memory warning when testing on iPhone 5 series on iOS7.
Changing
[self presentViewController:imagePicker animated:YES completion:nil];
to
[self presentViewController:imagePicker animated:YES completion:NULL];
fixed the issue for me.
I am trying access the Photo Library from an iPad application. It is said that "On iPad, UIImagePickerController must be presented via UIPopoverController". That's exactly the log message that I get too.
Here is a snapshot of my app:
Since I am already listing the options via a popover, it doesn't make sense to go another popover from within. The accessPhotoLibrary method gets called when the user taps on the "Photo Library" cell.
-(void)accessPhotoLibrary{
NSLog(#"Photo library access requested!");
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
NSLog(#"Photo Library");
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
[imagePickerController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:imagePickerController animated:YES completion:nil];
}
else{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Photo Library"
message: #"Sorry, couldn't open your photos library"
delegate: nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
But how do I get around this problem of having to access the photo library using a popover when I am using one already??
Any help is much appreciated.
You can present the image picker within the same popover. Hold a reference to the popover (the parent view controller presenting the popover can pass a reference) and then you can do the following:
[_parentPopover setContentViewController:imagePickerController animated:YES];
If needed, you can change the size of the content presented in the popover using the property "contentSizeForViewInPopover" in the image picker view controller.