开发者

Getting exception when try to PresentModalViewController

I am implementing a MFMailComposeViewController in my application. When I try to open the mail composer by using following code I am getting exception like "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target". I don't know what is wrong I made. Can you guys please take a look at my following code and suggest me.

   [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil ];

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate =self ;
controller.delegate=self;
controller.title=@开发者_Go百科"Title";
[controller setSubject:@"See my Notes"];
NSArray* toRecipients=nil;  

[controller setToRecipients:toRecipients];

NSString *emailBody = @"";
emailBody = @"<html><head><title><style type=\"text/css\">a {color: red}</style>";
emailBody = [emailBody stringByAppendingString:@"</title></head><body style='background-color: transparent;color:black'> "];
emailBody = [emailBody stringByAppendingString:@"Hello all"];
emailBody = [emailBody stringByAppendingString:@"</body></html>"];
[controller setMessageBody:emailBody isHTML:YES];

[self presentModalViewController:controller animated:YES];

Thanks in advance, -Sek.


Hmm... I've seen similar problems / crashes when sending an email on a device with no email client configured (but it's not a problem in simulator).

You can test for such cases like this...

// viewWillAppear

if (![MFMailComposeViewController canSendMail]) sendEmailButton.enabled = NO;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜