我正在开发 iPhone 应用程序的一部分,您可以在其中使用 iPhone 3.0 中的应用程序内邮件发送图像。从相机胶卷中选择图像效果很好,但是当我尝试从相机转到电子邮件时(即 - 从 UIImagePickerController 到 MFMailComposeViewController),应用程序崩溃了。
这是运行相机的代码:
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegateObject
{
if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil))
return NO;
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = delegateObject;
picker.allowsImageEditing = NO;
[controller presentModalViewController:picker animated:YES];
return YES;
}
这是使用相机完成的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSLog(@"Called finish picking");
self.imageForSending = theImage;
// NSData *imageData = UIImageJPEGRepresentation(image, 1);
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] recoverNavigationBar];
[self performSelector:@selector(sendEmail) withObject:nil afterDelay:0.45];
[picker release];
}
这是发送邮件的代码:
- (void) sendEmail {
[(ChannelTwoAppDelegate *) [[UIApplication sharedApplication] delegate] hideNavigationBar];
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"שגיאה", @"") message:NSLocalizedString(@"לא ניתן לשלוח מייל ממכשיר זה", @"")
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
else
{
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[[controller navigationBar] setTintColor:[UIColor colorWithRed:120.0/255.0 green:0 blue:0 alpha:1.0]];
NSData *imageData = UIImageJPEGRepresentation(imageForSending, 1);
[controller addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"storyImage.jpg"];
[controller setSubject:@""];
[controller setToRecipients:[NSArray arrayWithObject:@""]];
[self presentModalViewController:controller animated:YES];
[controller release];
}
}
我删除了电子邮件地址和主题,因为它不太相关。
崩溃发生在电子邮件的 presentModalViewController 上。再次 - 从相机胶卷中选择图像时,这个确切的代码完美地工作......
帮助 ?我已经和这个打了一段时间了,真的可以使用一些新的输入。谢谢!