2

我收到一个非常奇怪的错误 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];
}];

}

提前感谢任何人对此的帮助。

4

1 回答 1

2

我在我的应用程序中遇到了同样的错误,在 HUD 上点击手势。我的手势识别器方法是使用 HUD 上的块属性来执行必要的操作,并且它在哪里崩溃(块中的代码永远不会运行)。显然程序无法访问该代码,并且由于您还有一个完成块,它可能是正在发生的事情的线索。

我没有看到我在代码中做错了什么,而且您似乎也没有这样做,所以也许这是一个错误。您是否有机会运行 Xcode(4.4 或 4.5)的开发人员预览版?

编辑:原来我的问题是代码块属性在它有机会运行之前就被释放了。我认为在你的情况下可能会发生类似的事情,警报 var。您可以尝试在完成块内移动警报初始化吗?

编辑2:作为替代方案,尝试在警报初始化前加上__weak(或者__unsafe_unretained如果您的目标是iOS 4.3),应该这样做。如果您不使用 ARC,请__block改用。

于 2012-07-24T17:24:32.653 回答