iphone - 使用 MFMailComposeViewController 的问题

标签 iphone objective-c ios mfmailcomposeviewcontroller

我在使用 MFMailComposeViewController 时遇到问题。这是我尝试在设备上运行的示例代码。我特意添加了 5 秒的延迟(只是为了模拟下载附件文件的体验),之后应用程序显示“邮件” Controller 。在延迟期间,如果我们单击主页按钮,即让应用程序在后台运行并在 5 秒前恢复应用程序,主题字段将为空白,消息正文的值为“消息 1”而不是“消息 2” "如果我​​们最小化应用程序并在 5 秒后恢复应用程序,主题不会出现,但正文将是“消息 2”而不是“消息 1”。你能帮我理解这种行为吗?

-(void) func:(MFMailComposeViewController *) mail
{
    [mail setMessageBody:@"message 2" isHTML:NO];
    [self presentModalViewController:mail animated:YES];    
} 

- (IBAction)action:(id)sender 
{
    MFMailComposeViewController * mail = [[MFMailComposeViewController alloc] init];
    [mail setMailComposeDelegate:self];
    [mail setMessageBody:@"message 1" isHTML:NO];
    [mail setSubject:@"subject 1"];

  dispatch_async(dispatch_get_main_queue(), ^{    
        [self performSelector:@selector(func:) withObject:mail afterDelay:5];     
  });
}

谢谢

最佳答案

给你!

-(IBAction)email {
    MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [composer setMailComposeDelegate:self];
    if ([MFMailComposeViewController canSendMail]) {
        [composer setToRecipients:[NSArray arrayWithObjects:@"", nil]];
        [composer setSubject:@""];
        [composer setMessageBody:@"" isHTML:NO];
        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:composer animated:YES];
        [composer release];
    }
    else
        [composer release];
}

关于iphone - 使用 MFMailComposeViewController 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10346580/

相关文章:

c++ - 在 ObjC 中创建 csv 文件

iphone - CGContextClearRect 带圆圈

ios - 在 NSBatchDeleteRequest 之后使用核心数据

ios - 使用 initWithContentsOfFile iOS Objective C 创建的 NSMutableDictionary 的 setValue 方法中的错误访问错误

ios - 奥特莱斯显示为零

IOS - UIPageControl 在状态栏下方创建空间

ios - 在项目中有多个目标时如何使用结构

iphone - TouchUpInside 事件后无法将 UIButton 保持在选定状态

iphone - CAAnimation 在滚动出界时停止

iphone - 与 APNS 服务器交互以向 iOS 设备发送推送通知的最简单方法是什么?