Open camera view upon app Startup (iOS6)

2019-03-01 19:16发布

问题:

what im trying to do is to have the app open up with the camera as the first screen. It isn't working and i don't know what im missing. If anyone can fill me in that would be wonderful... Thanks.

    - (void)viewDidLoad
{


[super viewDidLoad];
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}


}

回答1:

Try like that. Hope it helps you:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

imagePicker.delegate = self;

[self presentViewController:imagePicker animated:YES completion:nil];