ImagePicker removing views when dismissed iOS 8 - ios

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.

Related

UIImagePickerController has issue "Snapshotting a view that has not been rendered results in an empty snapshot....." [duplicate]

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!

Xcode5 error : Warning attempt to present <View> on <OtherView> while presentation is in progress

I am still a noob when it comes to making applications for iOS and I don't understand why I am getting a certain error. For my current project I am trying to switch views but I cannot get it to work and I do not really understand why. I followed this tutorial for the button(http://www.youtube.com/watch?v=ph3XhJD8QAI) and although the tutorial is older, it still works. I had to edit some of the code to make sure that it worked for Xcode 5 though. Every time I press the button to switch the views I get an error that reads "Warning: Attempt to present < SecondView: 0xc918d50 > on < SeriouslyFunnyView: 0xc91a130 > while a presentation is in progress!" and the screen in the iPhone Simulator just goes black. I am also using Storyboard, i'm not sure if that is relevant to the situation or not. Can anyone possibly tell me what I am doing wrong ? Let me know if I need to add more code for clarification ! Thanks in advance for the help
Here is my code for the button that switches views
-(IBAction)SwitchView:(id)sender {
SecondView *second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
You must dismiss completely a view before present another. Try with:
[self dismissViewControllerAnimated:YES completion: ^{
SecondView *second =
[[SecondView alloc] initWithStyle:UITableViewStylePlain];
controller.modalTransitionStyle = UITableViewStylePlain;
[self presentViewController:second animated:YES completion:nil];
}];
comment the body of switchview, and check whether any controller is presented on click of switchview.. that looks silly but may be it'd b helpful to find out which controller is in progress... i'm also not used to storyboards ,, so .. hope that helps
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"orig image size: %#", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(#"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}

UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

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.

Simple view controller switch causes: Attempt to present while a presentation is in progress

I am learning how to handle view controller hierarchies using the storyboard. I have 2 ViewControllers: the root of type cwViewController (what I understand is 'self' below) and a second of type WorkspaceViewController. I am getting "Attempt to present while a presentation is in progress!" as a result of this code.
- (IBAction)nextView {
WorkspaceViewController *workspace = [[WorkspaceViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:workspace animated:YES completion:NULL]; }
The answer to How to present view controller properly? is the closest answer that could apply but doesn't quite fit this scenario because I'm not switching back and forth between VCs, I'm just presenting one, then dismissing it to display the original.
Then, I tried dismissing the current one before presenting the second, as some answers suggested, like this:
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:workspace animated:YES completion:NULL];
But that just gets me an additional Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress!
Doing some other research I saw similar problems were solved by adding a block to
[self dismissViewControllerAnimated:YES...]
But that doesn't help here because my warning occurs before I even get to a point where I call that dismiss method. Any further knowledge on how the order and hierarchy of views are meant to be handled would be a big help. Thanks very much.
Did you create a segue from the button to your WorkSpaceViewController? If so, you are likely attempting to present the WorkSpaceView twice - once when the button is selected and once from cwViewController. To eliminate the error, delete the segue from the button to WorkSpaceViewController and then recreate the segue - this time between cwViewController and the WorkSpaceViewController. That should take care of it.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"orig image size: %#", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(#"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
try
[self presentModalViewController:workspace animated:YES];
if (![[self modalViewController] isBeingPresented]) {
[self dismissModalViewControllerAnimated:YES];
}

iPad UIImagePicker Camera Tutorial

I have looking for a complete tutorial on google and stack of a complete example on using the UIImagePicker to get a picture from the camera and a picture from the library or camera roll on the iPad 2.
I have found code snippets saying just add the PopOverController in, but have not been able to implement it successfully.
thanks in advance.
This worked for me.
I do it like this I detect if iPhone or iPad and in the popover where it says (self.album.bounds) is just were you want the popover arrow to appear in this case self.album is the button that fires the below action
-(IBAction)selectPicture:(id)sender {
NSLog(#"Image is not set");
// Create image picker controller
thePicker = [[UIImagePickerController alloc] init];
// Set source to the camer roll;
thePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
// Delegate to self
thePicker.delegate = self;
//Allow editing of image NO
thePicker.allowsEditing = NO;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self presentModalViewController:thePicker animated:YES];
}
else{
popover = [[UIPopoverController alloc]initWithContentViewController:thePicker];
[popover presentPopoverFromRect:self.album.bounds inView:self.album permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
popover = popover;
}
}

Resources