【问题标题】:Mail Compose View Controller Won't Open From UIAlertController邮件撰写视图控制器不会从 UIAlertController 打开
【发布时间】:2016-07-28 03:14:20
【问题描述】:

从 UIAlertController 按下按钮后,我试图拉出一个邮件撰写视图控制器。在模拟器中,我在尝试打开邮件时总是在模拟器中收到正常的崩溃和错误消息,但在应用程序中,我什么也没得到。没有控制器,没有崩溃,什么都没有。这是代码。

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        [self emailThem];

        [self dismissViewControllerAnimated:YES completion:^{
        }];
    }]];

-(void) emailThem {
    NSLog(@"EMAIL");
    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    mail.mailComposeDelegate = self;
    [mail setSubject:@"To P3 Media"];
    [mail setMessageBody:@"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO];
    [mail setToRecipients:@[@"p3media2014@gmail.com"]];

    [self presentViewController:mail animated:YES completion:NULL];
}

有什么问题?

【问题讨论】:

  • 尝试在关闭视图控制器后将“[self emailThem]”放入完成处理程序中。还要确保方法 emailThem 下的 presentViewController 正在用户界面线程上运行。
  • @SeanMcDonald 好的,我试过 [self dismissViewControllerAnimated:YES completion:^{ [self emailThem]; }]; 但还是一样。
  • 您是否在设备上设置了电子邮件帐户?

标签: ios uialertcontroller mfmailcomposeviewcontroller


【解决方案1】:

试试这个代码

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Email" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

    [self emailThem];

    [self dismissViewControllerAnimated:YES completion:^{
    }];
}]];

-(void) emailThem {
    NSLog(@"EMAIL");
    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    mail.mailComposeDelegate = self;
    [mail setSubject:@"To P3 Media"];
    [mail setMessageBody:@"Replace this text with your message for all the information you would like on P3 Media." isHTML:NO];
    [mail setToRecipients:@[@"p3media2014@gmail.com"]];
    dispatch_async(dispatch_get_main_queue(),^{
        [self presentViewController:mail animated:YES completion:NULL];
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    相关资源
    最近更新 更多