我收到一个非常奇怪的错误MFMailCompseViewController。错误为"error:address不包含指向对象文件中某个节的节"。MFMailCompseViewController关闭并实际发送电子邮件后,应用程序崩溃。
这是特定于MFMailComposeViewController的,因为我试图以模式呈现一个纯视图控制器,但它很好地解决了问题。
这是我写给calland present mail composer的代码:
- (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 = @"nn<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];
}];
}
提前感谢任何人在这方面的帮助。
我的应用程序中出现了同样的错误,在HUD上点击手势。我的手势识别器方法是使用HUD上的块属性来执行必要的操作,它在那里崩溃(块中的代码永远无法运行)。显然,程序无法访问该代码,而且由于您还有一个完成块,这可能是正在发生的事情的线索。
我没有发现我在代码中做错了什么,而且你似乎也没有做错,所以也许这是一个错误。您是否有机会运行Xcode(4.4或4.5)的开发人员预览版?
编辑:原来我的问题是代码块属性在有机会运行之前就被释放了。我认为在您的情况下可能会发生类似的事情,比如alert var。您能尝试在完成块中移动alert init吗?
编辑2:作为一种替代方案,请尝试在警报初始化前添加__weak
(如果您的目标是iOS 4.3,则为__unsafe_unretained
)。如果您不使用ARC,请改用__block
。