我收到一个非常奇怪的错误 MFMailCompseViewController。错误是“错误:地址不包含指向目标文件中某个部分的部分”。MFMailCompseViewController 关闭并且电子邮件实际发送后,应用程序崩溃。
这是 MFMailComposeViewController 特有的,因为我试图以模态方式呈现一个普通的视图控制器,它可以很好地解散。
这是我写给 calland 的代码,并展示了邮件编写器:
- (void) emailImage:(UIImage *)img {
//verified that the image is being returned correctly
UIImage *img1 = [[_delegate photoBrowser:self photoAtIndex:0] underlyingImage];
MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
mfViewController.mailComposeDelegate = self;
NSString *subject = @"Check out this photo I took - Cap That App";
[mfViewController setSubject:subject];
NSData *imgData = UIImageJPEGRepresentation(img1, 1.0);
[mfViewController addAttachmentData:imgData mimeType:@"image/jpg" fileName:@"photo.jpg"];
NSString *contactMessage = @"\n\n<a href=\"http://www.agilerocket.com\">Sent via Cap That - Available in the Apple App Store</a>";
[mfViewController setMessageBody:contactMessage isHTML:YES];
[self presentViewController:mfViewController animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Status:" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] autorelease];
switch (result) {
case MFMailComposeResultCancelled:
alert.message = @"You chose not to send the email.";
break;
case MFMailComposeResultSaved:
alert.message = @"Your email was saved as a draft. It has not been sent yet.";
break;
case MFMailComposeResultSent:
alert.message = @"Your email has been sent!";
break;
case MFMailComposeResultFailed:
alert.message = @"There was an error sending the email. Please verify your email is working and try again.";
break;
default:
alert.message = @"You chose not to send the email.";
break;
}
[self dismissViewControllerAnimated:YES completion:^(void) {
[alert show];
}];
}
提前感谢任何人对此的帮助。