在没有添加邮件帐户的情况下,在设备上单击撰写邮件时,我的应用程序崩溃。任何人都知道我可能做错了什么。如有任何帮助,我们将不胜感激。
- (IBAction)sendMail:(id)sender {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
NSArray *recipients = [NSArray arrayWithObject:@""];
mail.mailComposeDelegate = self;
[mail setSubject:@""];
[mail setToRecipients:recipients];
[self presentViewController:mail animated:YES completion:NULL];
}
每当您询问有关所得到错误的问题时,都应该包含一条完整的错误消息。
但根据你的描述,你应该做以下事情:
- (IBAction)sendMail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[self presentViewController:mail animated:YES completion:NULL];
} else {
// let user know they can't send email
}
}
还要注意,如果您没有任何要设置的值,则没有理由设置主题或收件人。