2011-06-16 64 views
1

当我尝试在设备上使用MFMailComposeViewController时,我得到下面给出的崩溃日志。iPhone:电子邮件API MFMailComposeViewController在设备上崩溃

当我尝试在模拟器上运行它时,它会打开模态视图。

这是我使用的代码:

stringHTMLhtml是HTML字符串。

stringHTML属于NSString类型,而html属于NSMutableString类型。

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 
    mailController.mailComposeDelegate = self; 
[mailController setSubject:@"Email"]; 
NSLog(@"%@",html); 
NSString *stringHTML=html; 
NSLog(@"%@",stringHTML); 
[mailController setMessageBody:stringHTML isHTML:YES]; 
[self presentModalViewController:mailController animated:YES]; 
[mailController release]; 

什么可能是错的?

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <QuizReportsView: 0x411af0>.' 
*** Call stack at first throw: 
(
0 CoreFoundation      0x3737364f __exceptionPreprocess + 114 
1 libobjc.A.dylib      0x33a30c5d objc_exception_throw + 24 
2 UIKit        0x31350fcf -[UIViewController presentModalViewController:withTransition:] + 546 
3 UIKit        0x31350cd7 -[UIViewController presentModalViewController:animated:] + 58 
4 Vocab        0x0007d1bf -[QuizReportsView actionSheet:clickedButtonAtIndex:] + 270 
5 UIKit        0x313c603d -[UIActionSheet(Private) _buttonClicked:] + 192 
6 CoreFoundation      0x372e3571 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24 
7 UIKit        0x312c3ec9 -[UIApplication sendAction:to:from:forEvent:] + 84 
8 UIKit        0x312c3e69 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32 
9 UIKit        0x312c3e3b -[UIControl sendAction:to:forEvent:] + 38 
10 UIKit        0x312c3b8d -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356 
11 UIKit        0x312c4423 -[UIControl touchesEnded:withEvent:] + 342 
12 UIKit        0x312c2bf5 -[UIWindow _sendTouchesForEvent:] + 368 
13 UIKit        0x312c256f -[UIWindow sendEvent:] + 262 
14 UIKit        0x312ab313 -[UIApplication sendEvent:] + 298 
15 UIKit        0x312aac53 _UIApplicationHandleEvent + 5090 
16 GraphicsServices     0x31c36e77 PurpleEventCallback + 666 
17 CoreFoundation      0x3734aa97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26 
18 CoreFoundation      0x3734c83f __CFRunLoopDoSource1 + 166 
19 CoreFoundation      0x3734d60d __CFRunLoopRun + 520 
20 CoreFoundation      0x372ddec3 CFRunLoopRunSpecific + 230 
21 CoreFoundation      0x372dddcb CFRunLoopRunInMode + 58 
22 GraphicsServices     0x31c3641f GSEventRunModal + 114 
23 GraphicsServices     0x31c364cb GSEventRun + 62 
24 UIKit        0x312d5d69 -[UIApplication _run] + 404 
25 UIKit        0x312d3807 UIApplicationMain + 670 
26 Vocab        0x00002223 main + 82 
27 Vocab        0x000021cc start + 40 
) 
terminate called after throwing an instance of 'NSException' 

回答

7

从错误很明显,您提出了一个nil模态视图控制器。

检查MFMailComposeViewController的对象是否正确构造或不正确。

And AsloMFMailComposeViewController提供在iOS 3.0及更高版本。

与下面的代码

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 
if(mailController) 
{ 
    mailController.mailComposeDelegate = self; 
    [mailController setSubject:@"Email"]; 
    NSLog(@"%@",html); 
    NSString *stringHTML=html; 
    NSLog(@"%@",stringHTML); 
    [mailController setMessageBody:stringHTML isHTML:YES]; 
    [self presentModalViewController:mailController animated:YES]; 
    [mailController release]; 
} 

尝试以下更多的检查。

Application tried to present a nil modal view...

Problem with Modal View Controller

+2

非常感谢。它没有工作:)邮件帐户没有在我的设备中设置。所以分配没有发生。 – 2011-06-16 13:02:14

11

试试这个

//check if device is configured to send mails 
if([MFMailComposeViewController canSendMail]){ 
    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; 
    if(mailController) 
    { 
    mailController.mailComposeDelegate = self; 
    [mailController setSubject:@"Email"]; 
    NSLog(@"%@",html); 
    NSString *stringHTML=html; 
    NSLog(@"%@",stringHTML); 
    [mailController setMessageBody:stringHTML isHTML:YES]; 
    [self presentModalViewController:mailController animated:YES]; 
    [mailController release]; 
    } 
} 
+0

+1这是可能的情况。 – 2011-06-16 12:40:45

+0

@Deepak谢谢。 – 2011-06-16 12:41:58

+0

@Deepak你的邮件ID是什么?我需要一点点的帮助。 – 2011-06-16 12:43:24

相关问题