我已经设置了一个MFMailComposeViewController,它在iPhone上工作得很好,但是在iPad上它崩溃了,它说:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target...那么为什么这会创建一个nil模式视图呢?
MFMailComposeViewController *message = [[MFMailComposeViewController alloc] init];
[message setMessageBody:@"My message here" isHTML:NO];
[message setToRecipients:[NSArray arrayWithObject:@"my@domain.com"]];
[message setSubject:@"Request Info"];
message.mailComposeDelegate = self;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
message.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:message animated:YES];
[message release];有什么想法吗?
发布于 2011-02-14 08:18:59
像MFMailComposeViewController这样的nil不是出于某种原因而创建的,因此具有Loo的价值。在演示之前检查它是否为nil (尽管此解决方法不能回答此处出现问题的原因...)。
在尝试使用+canSendMail方法创建和呈现邮件之前,您还应该检查邮件编写器是否可以发送邮件(它将返回NO,例如,如果设备上没有设置邮件帐户):
if ([MFMailComposeViewController canSendMail]){
// Create and show composer
}
else{
// Show some error message here
}发布于 2011-02-18 21:07:27
在创建MFMailComposerViewController对象之前,您必须放入check canSendMail,查看来自MFMailComposeViewController.h类的以下注释:
/*!
@method canSendMail
@abstract Returns <tt>YES</tt> if the user has set up the device for sending email.
@discussion The client may continue to set the recipients and content if the return value was <tt>YES</tt>. If <tt>NO</tt>
was the result, the client has a couple options. It may choose to simply notify the user of the inability to
send mail, or it may issue a "mailto" URL via <tt>-[UIApplication openURL:]</tt>.
*/
+ (BOOL)canSendMail __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);在您的设备设置为发送邮件之前,您的对象不会被初始化。
发布于 2013-06-29 17:58:25
if ([MFMailComposeViewController canSendMail]){
//execute your code
else{
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[anAlert addButtonWithTitle:@"OK"];
[anAlert show];
}如果您收到警报,请在手机上配置您的邮件帐户。
https://stackoverflow.com/questions/4987703
复制相似问题