Question for iPhone dev noob: invoke an action explicitly when the application starts

I just started developing iPhone. I studied in textbooks and materials from books to understand how to do it right. I come from the background of PHP and Java ... Objective-C is a bit freaky. But I learn best when my legs are wet.

Basically, I have these actions. getPhoto is bound to several UIBarButtonItems, in my opinion.

-(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 trigger the same action after starting the application, automatically opening the camera. How can i do this?

+3
source share
1 answer

EDIT:

In accordance with this SO question, you should place it in viewWillAppearorviewDidAppear


ApplicationDidFinishLaunching .

, ViewDidLoad

+3

Source: https://habr.com/ru/post/1734614/


All Articles