0
我完全不知所措。我試圖讓用戶通過MFMailComposeViewController發送一封電子郵件。然而,當我建立了我的MFMailComposeViewController用HTML機構,MFMailComposeViewController正確顯示的電子郵件,但與日誌這樣發送郵件我的應用程序崩潰:設置HTML正文時,MFMailComposeViewController在iOS5上崩潰
2011-12-03 15:04:08.708 Kinopilot[58387:17503] *** Terminating app due to uncaught
exception 'DOMException', reason: '*** INVALID_ACCESS_ERR: DOMException 15'
*** First throw call stack:
(0x2994052 0x210fd0a 0x2993f11 0x391affb 0x3886795 0x64a9b4 0x6487b6
0x648b84 0x648bb4 0x648bb4 0x6424b9 0x69078b 0x658fad 0x658eeb 0x658e6f
0x656d37 0x656bb2 0x65737c 0x65759e 0x658273 0x658758 0x6588e6 0x2995ec9
0x10965c2 0x12d1d54 0x2995ec9 0x10965c2 0x109655a 0x113bb76 0x113c03f
0x113b2fe 0x10bba30 0x10bbc56 0x10a2384 0x1095aa9 0x2270fa9 0x29681c5
0x28cd022 0x28cb90a 0x28cadb4 0x28caccb 0x226f879 0x226f93e 0x1093a9b 0x6680d 0x663d5)
我非常確信MFMailComposeViewController是有線正確,因爲當我將主體設置爲純文本時,一切都很好。此外,我的代碼在iOS 4.3上工作正常,具有HTML和純文本。
這是相關代碼:
@interface MailComposeDelegate: NSObject<MFMailComposeViewControllerDelegate>
@end
@implementation MailComposeDelegate
+(MailComposeDelegate*) sharedMailComposeDelegate
{
static MailComposeDelegate* mcd = nil;
if(!mcd) {
mcd = [[MailComposeDelegate alloc]init];
}
return mcd;
}
-(void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[app.window.rootViewController dismissModalViewControllerAnimated:NO];
}
...
@implementation M3AppDelegate(Email)
-(void)composeEmailWithSubject: (NSString*)subject
andBody: (NSString*)body
{
// -- compose HTML message.
MFMailComposeViewController* mc;
if([MFMailComposeViewController canSendMail])
mc = [[MFMailComposeViewController alloc] init];
if(!mc) return;
mc.mailComposeDelegate = [MailComposeDelegate sharedMailComposeDelegate];
[mc setSubject: subject];
[mc setMessageBody: body isHTML: YES];
// -- show message composer.
[app.window.rootViewController presentModalViewController:mc animated:YES];
}
@end