我在我的iPhone应用程序中使用相机,当我在iPad2中打开此应用程序时,当我点击相机按钮时它会崩溃..
以下是我使用相机的代码
-(void) loadCamera{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePickerController setDelegate:self];
[imagePickerController setAllowsEditing:YES];
[self presentModalViewController:imagePickerController animated:NO];
[imagePickerController 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];
}
此代码在iPhone上运行良好但在iPad2上崩溃。
我的应用程序不适用于iPad .....而是在iPad上使用2x运行它
请帮忙。
答案 0 :(得分:0)
您应该首先检查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];
}