camera code crash on iPad2
I am using camera in my iPhone app and when i open this app in my iPad2 it crashes when i click that camera button..
Here is my code for using camera
-(void) loadCamera{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePickerController setDelegate:self];
[imagePickerController setAllowsEditing:YES];
[self presentModalViewController:imagePickerController animated:NO];
[imageP开发者_高级运维ickerController release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
// UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
// [alert show];
// [alert release];
[picker dismissModalViewControllerAnimated:YES];
// // Access the uncropped image from info dictionary
// UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.cameraimage.image=image;
self.tinyImage.image=image;
// Make the needed component visible
self.cameraimage.hidden=NO;
self.RemoveImage.hidden=NO;
self.RetakePicture.hidden=NO;
self.addphoto.hidden=YES;
// Save image
[constants saveImage:image withName:self.largeImageName];
[constants saveImage:image withName:self.tinyImageName];
}
This code works good on iPhone but on iPad2 it crashed.
My app is not for iPad .....but running it by using 2x in iPad
please help.
You should always first check the isSourceTypeAvailable: first
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if([UIImagePickerController isSourceTypeAvailable:sourceType])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
if(sourceType == UIImagePickerControllerSourceTypeCamera)
[picker takePicture];
[self presentModalViewController:picker animated:YES];
[picker release];
}
精彩评论