Iphone Memory Warning when camera shows - iphone

i have a TabBarController in which one tab has an ImageView. Besides, i have a button to display the ImagePicker:
- (IBAction)choosePhoto {
// Create image picker controller
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
[imagePicker setAllowsEditing:NO];
// Show image picker
[tabBarController presentModalViewController:imagePicker animated:NO];
But the problem is that when i press the button in order to launch the ImagePicker i get the message: Received memory warning. Level=1/ Level=2.
I've tried to change the delegate to the View of the tab but it doesn't works neither.
Any idea?
Thanks

A memory warning per se is not a problem. The camera needs an awful lot of memory so it is very common that the system generates a memory warning whenever the camera interface is being displayed. Just make sure to free as much memory as possible in reaction to the warning.

Related

How can I make the camera appear every time I click a specific tab?

info: xcode 4.3.2, iOS5, using storyboard.
Created project from xcode's "Tabbed Application" template.
Did:
#implementation SUSecondViewController
UIImagePickerController *pic;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
pic = [[UIImagePickerController alloc] init];
pic.delegate = self;
// [pic setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:pic animated:YES];
}
When I click the tab the first time, the camera app is displayed.
When I click the tab the second time, the default view from the template is displayed, however I want the camera to be displayed every time the tab is clicked.
How can I make the camera appear every time I click a specific tab (with f.ex. a camera icon) ?
viewDidLoad only happens when the view is loaded.
If a view disappears / reappears it's not guaranteed that the view will get unloaded / loaded.
Maybe because there still is a strong pointer to the viewController somewhere, and the system doesn't need to free up some memory.
If you want to get it called every time the view appears, place that code in UIViewControllers
- (void)viewDidAppear
method instead of
- (void)viewDidLoad
You might also want to take a look here:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ViewLoadingandUnloading/ViewLoadingandUnloading.html#//apple_ref/doc/uid/TP40007457-CH10-SW1
Use it on viewDidAppear: as on viewDidLoad you may not get some UI related things working as Nib is not completely loaded until viewDidLoad has finished executing.
So I would like you to code this on viewDidAppear: as shown below
#implementation SUSecondViewController
UIImagePickerController *pic;
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Do any additional setup after loading the view, typically from a nib.
pic = [[UIImagePickerController alloc] init];
pic.delegate = self;
// [pic setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentModalViewController:pic animated:YES];
}
Hope this helps you.

use camera as subview

i'm using UIImagePickerControllerSourceTypeCamera in my app, but a want to add the camera view a subview. not as modal view.
now i'm using
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
i want to use it like this, but doesn't seem to work ..
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
[picker.view setFrame:CGRectMake(300, 40, 300, 200)];
[self.view addSubview:picker.view];
i know that the UIImagePickerControllerSourceTypeCamera only can be used as modal view.
How is for example Hipstamatic using this for example?
This is possible in iOS 4+ using the AVCaptureSession framework. It's much more complicated than using UIImagePickerController, but you have complete control over input and output. The key to having the camera view as a subview is the following code. Assume you have a subview called previewView that you want to show the camera view:
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
previewLayer.frame = self.previewView.bounds;
[self.previewView.layer addSublayer:previewLayer];
There is more setup work to do to give your AVCaptureSession object the correct input and output devices and to actually capture the photos. That can be found in the documentation and examples on the web.
You're right, the only supported methods for displaying a UIImagePickerController seem to be presentModalViewController:animated: or UIPopoverController.
I'm not familiar with Hipstamatic, but chances are it is using AVFoundation, in particular AVCaptureVideoPreviewLayer.
Visit link to get idea how things can be accomplished. Look out for AVCam Demo in developer.apple.com resources for IOS programme. You will definitely get idea how it works. You should be registered developer with APPLE, and thats very easy.
Hope it helps.

iPhone: UIImagePickerController - standard zoom control doesn't work

I have a UIImagePickerController that is presented as a modal view controller. This works fine, except for when I try to add anything to the camera overlay view.
As soon as I modify the camera overlay view, the default zoom control stops working (although tap to focus still works). If I tap on the view, the zoom slider appears, but I am not able to slide it up and down like usual.
Here's the code I'm using:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
imagePickerController.wantsFullScreenLayout = NO;
[imagePickerController.cameraOverlayView addSubview:overlayView];
[self presentModalViewController:imagePickerController animated:YES];
Has anyone had a similar problem or can see what I'm doing wrong? I know it should work, as I've seen it on other apps that also use the default camera controls.
Thanks :)
After a lot of mucking round I've finally come across a solution. Don't use the cameraOverlayView property, instead add a subview to the UIImagePickerController with a frame of size CGRectZero.
In the following example, overlayView is a custom subclass of UIView which draws an image and passes touches through to the next responder:
OverlayView *overlayView = [[OverlayView alloc] initWithFrame:CGRectZero];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsEditing = NO;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = YES;
[imagePickerController.view addSubview:overlayView];
statViewController.imagePickerController = imagePickerController;
}
-
And then, everything just works. Not sure if adding a subview to UIImagePickerController is documented and ok with Apple, but heaps of other apps use this (or a similar workaround) so shouldn't cause any submission problems.

How to switch views when Iphone camera returns?

I am new to Iphone development. I am working on an application which involves two views. I have a camera button in view one which opens up the default Iphone camera. This is achieved by having this code in the IBAction for camera button in ViewOneController:
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
The view controller for the first view is also the UIImagePickerControllerDelegate for the camera. When the picture is clicked and the camera view returns to the function imagePickerController:didFinishPickingWithMediaInfo where I do this:
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[self presentModalViewController:ViewTwoViewController animated:YES];
}
So basically all I am trying to achieve is from viewone click "take picture" ---> Open camera --> after camera is done jump to view two. Quite simmilar to what it is in the flickr app. However after I take the picture from camera my app returns to view one and view two is not shown. What am I missing here?
Also from a conceptual perspective I guess IOS keeps a stack of views for any app. When presentModalViewController is called the view is shown and it is added to the stack and when dismissModalViewController is called the view is removed from the stack and the parent view is show. Is that right?
Thanks.
You probably need to put the call to [self presentModalViewController:ViewTwoViewController animated:YES] in viewWillAppear which will be called after the picker view has been removed.
You probably also need to surround the call with some check to only present viewTwo when applicable.

UIImagePickerController reloads view after its dismissed?

I create the picker:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
and I handle the didFinishPickingMediaWithInfo:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[picker release];}
but this calls the viewDidLoad on self. This is not normal is it? Whats wrong?
Your app probably received a memory warning, which caused all view controllers who are not displayed on screen to unload their views. This is quite normal while you are in the image picker because the camera needs a lot of memory. The moment you dismiss the image picker your view controller reloads its view.
As this is perfectly normal behavior, your app must deal with this situation correctly.
I had a similar issue with this, I was displaying a popup during a long press gesture. It appeared as though the modal was not dismissed after the image was selected. However, the long press gesture event gets called several times, so a new popup was being displayed for every event. In my gesture handler I do something like this as to fix:
if (![imagePickerPopoverController isPopoverVisible]){
//show pop-up etc
}
I had some kind of that issue and I'd tried to set presentation "Over full screen" and it worked without reloading