Question

I just started getting into iPhone development. I have been mish-mashing tutorials and material from books in order to get my bearings straight. I come from a PHP and Java background... Objective-C is a bit quirky. But, I learn best by getting my feet wet.

Basically, I have these actions. getPhoto is bound to a couple of UIBarButtonItems in my view.

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIBarButtonItem *) sender == choosePhoto) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    theimageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

My goal is to invoke the same action once the application launches, automatically opening the Camera. How would I go about this?

Was it helpful?

Solution

EDIT:

As per this SO question you should actually place it in viewWillAppear or viewDidAppear


Add a similar method to the ApplicationDidFinishLaunching method in the app delegate.

Might be better to place the call in the ViewDidLoad of your root view controller

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow