我有MFMailComposer
的这段代码在模拟器和iPhone 4中正常工作,但它在3GS上崩溃了。是什么原因以及解决方法是什么?
我用断点检查了它。 mailPicker
未分配内存。
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
// Set the subject of email
[mailPicker setSubject:@"Somebody got place in my sh*t list"];
NSString *emailBody = @"I just added somebody to my s**t list";
// This is not an HTML formatted email
[mailPicker setMessageBody:emailBody isHTML:NO];
// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation([self captureScreen]);
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[mailPicker addAttachmentData:data mimeType:@"image/png" fileName:@"CameraImage"];
// Show email view
[self presentModalViewController:mailPicker animated:YES];
// Release picker
[mailPicker release];
答案 0 :(得分:3)
如果设备上至少启用了一个电子邮件帐户,则以下呼叫应返回YES:
[MFMailComposeViewController canSendMail]
相反,如果所有帐户都被禁用/删除,它将返回NO。