views:

140

answers:

1

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?

+3  A: 

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

Griffo
Like this? [self getPhoto];Or how?
Hunter Bridges
Well yeah, you don't want to use sender from the app delegate though. You might need to alter your existing method or launch one similar since sender in this case will be the app delegate
Griffo
see edit and the answer from jm below. In this case the viewDidLoad method is probably more appropriate
Griffo
have you put `UIImagePickerControllerDelegate` in the header file of your app delegate?
Griffo