MFMailComposerViewController对象未在iPad中分配,但在模拟器中运行良好



当我alloc/initMFMailComposerViewController时,它没有被分配,对象是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:我认为首先你需要从设备的设置中添加帐户。如果你还没有从设置中添加帐户,那么你会遇到这种类型的问题。

步骤2:属性化和合成您的MFMailComposeView ControllerObject

最新更新