MFMailComposerViewController对象未在iPad中分配,但在模拟器中工作正常

时间:2014-09-24 05:40:08

标签: ios objective-c email mfmailcomposer

alloc / init MFMailComposerViewController时尚未分配,对象为nil。应用程序在呈现mailViewController时崩溃了。这是我的代码:

MFMailComposeViewController  *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

[picker setSubject:@"Photos"];

NSString *body = [NSString stringWithFormat:@"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"
                  "<html>"
                  "<head>"
                  "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"
                  "</head>"
                  "<body>"
                  "%@"
                  "</body>"
                  "</html>",[NSString stringWithFormat:@"Picture from %@",APP_NAME]];

[picker setMessageBody:body isHTML:YES];

NSData* data = UIImagePNGRepresentation(self.sharedImage);

[picker addAttachmentData:data mimeType:@"image/png" fileName:APP_NAME];
[self presentViewController:picker animated:YES completion:nil];

1 个答案:

答案 0 :(得分:2)

步骤1:我认为首先您需要从设备设置中添加帐户。如果您尚未从设置中添加帐户,则会遇到此类问题。

步骤2:对MFMailComposeView ControllerObject进行属性化和合成