9

I have an app which uses the UIImagePickerController to allow the user to take photos.

I have reduced the test case to the simplest sequence in a single view controller app. Here is my code.

//
//  CTViewController.h
//  Camera Test
//

#import <UIKit/UIKit.h>

@interface CTViewController : UIViewController <UINavigationControllerDelegate,   UIImagePickerControllerDelegate>

@property (nonatomic, retain) UIImagePickerController *cameraController;

- (IBAction)takePicture:(id)sender;

@end

the body of the code is as follows:

//
//  CTViewController.m
//  Camera Test

#import "CTViewController.h"

....

- (void)didReceiveMemoryWarning
{
    NSLog(@"%s", __func__);

    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)takePicture:(id)sender
{
    self.cameraController = [[UIImagePickerController alloc] init];

    self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.cameraController.allowsEditing = YES;
    self.cameraController.delegate = self;
    [self presentViewController:self.cameraController animated:YES completion:nil];
}

'takePicture' is hooked up to a button I can press in the middle of the screen.

On ios 6 everything works perfectly, but on ios 7 I get a cascade of memory warnings once the viewcontroller is presented. Thus:

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.
Received memory warning.
-[CTViewController didReceiveMemoryWarning]

.... <here I take a picture, which I do nothing with>

Received memory warning.
-[CTViewController didReceiveMemoryWarning]
Received memory warning.
-[CTViewController didReceiveMemoryWarning]

.... <I get a cascade of these warnings>

The app is built using the ios 7.0 sdk using xcode 5. The same problem occurs if I build with the ios 6.1 sdk, but run on ios7. Building with the ios 6.1 sdk and running on ios 6.1.3 causes no messages and no problems.

My complete app crashes 50% of the time on ios 7. I respond to the memory warning by throwing a lot of stuff (images mostly) out of memory and profiling confirms this, but I still get the cascade of warnings (i.e. they continue after the memory is freed).

If I use the front camera, choose from the gallery or use an iPad 3, there are no messages. I therefore suspect that the memory problem is associated with the size of the UIImagePickerController when the rear camera is used.

I have fully explored stackoverflow and have looked particularly at this post - UIImagePickerController error: Snapshotting a view that has not been rendered results in an empty snapshot in iOS 7

I have tried everything suggested, but my simple test app precludes most of the explanations.

Any thoughts? Should I abandon support for the iPhone 4S? I have no yet confirmed the problem on the iPhone 5, but I will update this question as soon as I have.

:-)

Community
  • 1
  • 1
  • We are also running into the same issues with the camera crashing after reviewing and accepting a photo on an iPhone 4s with iOS7. – Edwin Liang Oct 16 '13 at 20:05
  • 4
    This is odd so I'm not offering it as an answer. I had the exact same issue but on an iPhone 5s. Spend 4 hours pouring over stack overflow and asking around. Finally, I rebooted my iPhone 5s and poof, no more memory warnings. They may return but after 2 hours of taking photos with the problem app, still no memory warnings. Weird! – JimVision Oct 17 '13 at 02:22
  • This seems to "fix" it. What the hell... – Zoltán Matók Nov 26 '13 at 10:13
  • maybe it's linked to the fact that ios7 try to take snapshot views of your app in order to show it in the control panel – Nicolas Manzini Nov 26 '13 at 10:36
  • I spent half a day debugging it when Jim's answer to reboot solved it... Jim please submit it as an answer! – Shai Almog Feb 03 '14 at 11:15

1 Answers1

3

I would recommend you not using a property for the image picker, have a local object instead. See below my code that works fine on IOS7 as well.

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.showsCameraControls = YES;

    [self presentViewController:imagePicker animated:YES completion:nil];
}
Calin Chitu
  • 1,099
  • 7
  • 13
  • Can you expand on this suggestion? I have an app with a custom overlay and I pass a ref of the imagePicker into the overlay controller so I can call takePhoto inside the overlay IBAction: **[self.cameraPickerRef takePicture]** – Kevin Zych Oct 16 '13 at 19:00
  • Also, when I toggle the camera device, I add a custom black subview to self.imagePicker.view so the transition is a bit nicer. In this method, I need a reference to the imagePicker to add the subview and set the camera device. – Kevin Zych Oct 16 '13 at 19:03
  • That way it gets deallocated as soon as you take your photo, but if you need a strong reference, than it's more complicated. – Calin Chitu Oct 17 '13 at 07:30
  • 1
    Well, I suppose the strong reference inside my CameraViewController _could_ be eliminated but I would still need a reference to the picker in my CameraOverlayViewController so I can actually call takePhoto. I'm just not sure that eliminating the strong ref will be the cure, especially since this has been specific to iPhone 4S. I am keen about setting **self.imagePicker = nil** in the appropriate places. – Kevin Zych Oct 17 '13 at 20:11
  • I am having the same problem and I have tried both the SDK versions as well. It does only give memory warnings on iPhone4 iOS7 but on iPhone4 ioS7 it crashes most of the time. – ShayanK Oct 29 '13 at 17:58
  • I would not store the raw image in a property because the raw image takes up roughly 30MB of memory. As far as I am aware the iPhone 5 can handle this but the iPhone 4 series cannot. – DevC Dec 10 '13 at 11:44
  • I changed the property attribute from strong to weak, and the error message went away for me. EDIT: but then tried again later and it came back... – shim Feb 06 '14 at 22:30
  • Are there any solutions of this one I am facing same issue – Susim Samanta Jun 07 '14 at 04:34