【问题标题】:Mock the MFMailComposeViewController on iOS simulator. Just need to display the composer在 iOS 模拟器上模拟 MFMailComposeViewController。只需要显示作曲家
【发布时间】:2017-12-15 07:59:24
【问题描述】:

我只需要在我的 iOS 模拟器上显示电子邮件撰写器(无需发送实际邮件)。

当我初始化 MFMailComposeViewController 时,我会弹出警报 - 提示电子邮件帐户未设置。

这就是我正在做的。

MFMailComposeViewController* composeVC = [[MFMailComposeViewController alloc] init];

此行弹出警报控制器。

【问题讨论】:

    标签: ios objective-c mfmailcomposeviewcontroller


    【解决方案1】:

    对于模拟器电子邮件配置不可用。

    使用以下代码发送电子邮件。

    - (void)openEmail
    {
        if ([MFMailComposeViewController canSendMail])
        {
            MFMailComposeViewController *mail =
            [[MFMailComposeViewController alloc] init];
            mail.mailComposeDelegate = self;
            [mail setSubject:@"Subject"];
            [mail setMessageBody:@"body message" isHTML:NO];
            [mail setToRecipients:@[@"email1@example.com",@"email2@example.com"]];
            /// if attachment then implement below line
            //[mail addAttachmentData:<#(nonnull NSData *)#> mimeType:<#(nonnull NSString *)#> fileName:<#(nonnull NSString *)#>]
            [self presentViewController:mail animated:YES completion:NULL];
        }
        else {
            NSLog(@"Please configure your email. Settings->Accounts & Passwords->Add Account");
        }
    }
    
    - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(nullable NSError *)error
    {
        switch (result) {
            case MFMailComposeResultSent:
                NSLog(@"Sent");
                break;
            default:
                break;
        }
    }
    

    【讨论】:

    • 是否可以仅使用模拟器显示电子邮件编写器?我不需要使用实际的电子邮件功能。
    • 模拟器我不认为
    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2013-02-15
    • 1970-01-01
    相关资源
    最近更新 更多