我在我的demp app中实现MFMailComposeViewController
。但是,由于某些原因,我触摸后在电子邮件文本字段中添加文本后,我的应用程序崩溃了。但是发送没有添加任何文本的工作正常。
我的Xcode没有显示太多。这是我得到的:
我已经在电子邮件文本字段中设置了初始文本。也许这个问题在这里?请求任何代码,我很乐意将其包含在内。
更新
这里有两种方法,当触摸openMail
UIButton
会触发
- (IBAction)openMail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Feedback from Demo App user"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"myEMAIL@hotmail.com", @"myEMAIL2@gmail.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = @"Happy to hear your feedback!";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}
// Remove the mail view
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:0)
可能你正在使用ARC,并且你没有强烈指向你的MFMailComposeViewController
,并且在显示之后,ARC正在释放它。
使用
@property (nonatomic,stron) MFMailComposeViewController *mail;
当你初始化MFMailComposeViewController时:
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
self.mail = mailer;
答案 1 :(得分:0)
你的代码中是否还有这一行:
[mailer release];
如果是这样就是问题所在。如果没有,那么请更新我们的代码示例,使其正是您现在正在使用的。