MFMailComposeViewController
我从我的自定义类(不是 viewController)中呈现。在 iOS5 中它工作正常,但在 iOS6 中它在呈现撰写表后立即崩溃。我发现了在呈现视图后调用 dealloc 方法的问题,因此 self 正在解除分配。由于这个 mailcomposer 不能调用 self 的委托方法,所以它崩溃了。我没有得到解决方案。我正在使用ARC。如何防止self
在调用委托方法之前解除分配?
-(void)shareOnViewController:(UIViewController *)viewController completion:(ShareCompletionHandler)completion
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[mailer setSubject:[self.userInfo objectForKey:@"title"]];
NSData *imageData = UIImagePNGRepresentation([self.userInfo objectForKey:@"image"]);
if (imageData) {
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"AttachedImage"];
}
NSURL *emailBody = [self.userInfo objectForKey:@"url"];
if (![emailBody isEqual:@""]) {
[mailer setMessageBody:[emailBody absoluteString] isHTML:NO];
}
[viewController presentModalViewController:mailer animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unable to send mail"
message:@"Device is not configured to send mail"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
self.completionHandler = completion;
}