19

As the title states the app that I am developing has an issue that is caused only when the app is relaunched after entering the background.

The camera iris or shutter gets stuck in the closed position. The funny thing is you can still take a picture but you cannot see the preview. Once the picture is taken, it is shown correctly in the view.

This issue does not happen when the app is launched if the app is completely closed. I can take pictures, add effects and so on, every time the camera is opened it works correctly.

Here are the exact steps to reproduce the issue:

1) I open the app, everything works fine.

2) The app enters the background either by pressing the home button or incoming call.

3) When the app enters the foreground / reopened and the camera is accessed the shutter screen is shown and remains closed in the stuck position.

4) The only way to fix it is to dismiss the modal view camera controller and press the camera button again.

I have done some research to find an answer and have come up with nothing. There are no memory leaks and I have checked the memory allocations in instruments and there is nothing unusual.

Hopefully someone has a solution, I appreciate the help.

Thank you in advance.

jrturton
  • 118,105
  • 32
  • 252
  • 268
dana0550
  • 1,125
  • 1
  • 9
  • 16
  • A bounty in rep is more traditional than cold hard cash! – jrturton Nov 10 '11 at 09:27
  • Jrturton, I would be glad to give out a bounty but I do not think I have enough reputation to give out rep points. I have only asked a few questions on SO. – dana0550 Nov 11 '11 at 00:37
  • You only need 50 points- that's two upvoted and accepted answers - you can do it! – jrturton Nov 11 '11 at 08:08
  • this is same my problem i check my code then i see the custome camera not call dealloc after fix it did not happend sorry about my english –  Nov 11 '11 at 08:43

7 Answers7

12

I'm having the exact same issue, but narrowed down a bit - it only happens with iOS 5. With some hints from other people talking about memory, I freed up as much memory as possible before presenting the UIImagePickerController and the problem stopped happening.

SWoo
  • 147
  • 1
  • 3
  • 7
  • How did you free up the memory? Did you release the current image? The issue happens even if I bring up the camera and do not take a picture. I will press the camera button, then cancel it, close the app, reopen it and I press the camera button the shutter stays closed. – dana0550 Nov 11 '11 at 19:52
  • 1
    freed up every image and data I could on the view controller calling presentModalViewController (went from 5.5 meg to 3.5 meg), this worked for a bit then 5.01 came out and a few releases later and the problem came back. I was keeping the uiimagepickercontroller around because I could see leak every time it was freed but this was a mistake - if I just keep reusing it while the user is running the app, and free it when they quit and alloc a new one the next time the user runs the app and takes a photo, it fixed the problem for me. – SWoo Dec 03 '11 at 05:49
  • 2
    What I ended up doing is what you said in your last comment. I released the imagePicker after every use and alloc'ed a new one every time it was called. This fixed the issue completely. No need to free up memory or anything like that. Thank you. – dana0550 Apr 09 '12 at 20:55
  • 2
    hi i have same problem but i cant release imagepicker as the app is in arc framework and it gives error in using release or autorelese in code – The iOSDev Apr 11 '12 at 07:07
  • Your way works fine too...I had overlays on the camera and doing this worked. Post it as an answer for everyone to see. You can release your `imagePickerController` immediately after you dismiss it to optimize memory. – tipycalFlow Jul 19 '12 at 07:26
  • I have the same problem, am using ios6. – Vineesh TP Aug 20 '13 at 02:49
6

I was having the same problem, running in an ARC project.

Press the camera button on my main screen, the imagePickerController would display, cancel the imagePickerController. Press the home button (close) the app. Come back to my app and press the camera button again. In this case the shutter would show and be stuck.

Using memory issues as the main clue - I found out that my overlay view had a strong reference to the imagePickerController. I changed this to a weak reference and the problem went away.

user1262701
  • 129
  • 1
  • 4
  • This fixed it for me as well -- I didn't change strong/weak references, as I only had a single reference to the ImagePickerController, but I did add a line to specifically set the reference to nil once I'm done getting the image from the camera. Seems to work. – Ben Wheeler Jun 07 '13 at 22:39
5

I think that when you have the problem, and try to take a photo with the Apple app, you have the problem there also. Isn't it ? If yes, you may restart the device to solve the problem. And apply dana's tip.

Oliver
  • 23,072
  • 33
  • 138
  • 230
4

When the app goes into background mode then you should dismiss the camera and represent it when the app regains focus.

logancautrell
  • 8,762
  • 3
  • 39
  • 50
  • Logan, Thanks for the quick reply. I should have made my questions a little clearer. The app has two views: Home View and Camera View. A button is pressed to access the camera view. The interesting this is when the app is closed when the camera view is shown, it restarts just fine and the shutter opens. The problem happens when the app is closed from the main screen. Then when the app is reopened and the user presses the camera button the camera modal view is presented with the shutter stuck in the closed position. Thanks. – dana0550 Nov 09 '11 at 01:01
2

I was having the same problem , Following solutions works for me. whenever you are presenting UIImagePickerController modally. init it and release it after the use. Hope it works for you also .

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.imagePickerController.showsCameraControls = NO;

    self.imagePickerController.cameraOverlayView = cameraOverlayView;
} else {
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
}
[self presentViewController:imagePickerController animated:YES completion:^(void)
 {
   // If you want to do something extra
 }];
Ankit
  • 1,684
  • 14
  • 14
1

Just incase anyone hits this issue while using MonoTouch to get the same behaviour of releasing the Image Picker I had to call dispose and then do a manual GC.Collect();

Max
  • 1,543
  • 2
  • 16
  • 31
1

A combination of the following two worked for me

  1. Changed the reference type of overlay from 'strong' to 'weak'

  2. picker = nil , after dismissing the imagePickerController (on canceling or after taking the picture)

sm abbas
  • 1,008
  • 12
  • 13