Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to solve this error of Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'

Tags:

objective-c

I have working on pick the photo from gallery and save in gallery

my code is

-(void)onclicksave:(id)sender
{
    NSLog(@"onclicksave");
    UIImagePickerController *picker=[[UIImagePickerController alloc]init];
    picker.delegate=self;

    if((UIButton *)sender== openLibrary)
    {
        picker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    }
    else
    {
        picker.sourceType=UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];

}

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

}

but in this code run time error like

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'

so give any suggestion and source code which is apply in my code

like image 478
Barby Ashra Avatar asked May 21 '12 13:05

Barby Ashra


1 Answers

Well, this means what it says. UIImagePickerControllerSourceTypeCamera is a value from enum, equal to 1. You're trying to run your code on simulator or on device, that doesn't have camera.

like image 53
Denis Avatar answered Nov 16 '22 04:11

Denis