OStack程序员社区-中国程序员成长平台

标题: iphone - 发件人地址的 MFMailComposeViewController 问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 00:20
标题: iphone - 发件人地址的 MFMailComposeViewController 问题

我使用以下代码发送邮件:

- (IBAction)sendMailPressedid)sender
{
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
    {
        // We must always check whether the current device is configured for sending emails
        if ([mailClass canSendMail])
        {
            [self displayComposerSheet];
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}

// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;


    [picker setSubject:self.strMailSubject];

    // Attach pdf to the email
    NSURL *urlToLoad = [[NSBundle mainBundle] URLForResource:self.strSorce withExtension:self.strExtention];
    NSData *myData = [NSData dataWithContentsOfURL:urlToLoad];
    [picker addAttachmentData:myData mimeType"application/pdf" fileName:[NSString stringWithFormat"%@.%@", self.strSorce, self.strExtention]];

    //  [self presentModalViewController:picker animated:YES];
    [[Singleton sharedInstance] pushModalViewController:picker whereCurrentController:self animated:YES];
    [picker release];
}


// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeControllerMFMailComposeViewController*)controller didFinishWithResultMFMailComposeResult)result errorNSError*)error
{
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            break;
        case MFMailComposeResultSaved:
            break;
        case MFMailComposeResultSent:

            break;
        case MFMailComposeResultFailed:
            break;
        default:
            break;
    }

    [[Singleton sharedInstance] popModalViewControllerAnimated:YES];
}


// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
    NSString *recipients = [NSString stringWithFormat"mailto:&subject=%@", self.strMailSubject];

    NSString *email = [NSString stringWithFormat"%@", recipients];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}

我得到了这样的观点: enter image description here

但我需要这个 View (请只注意From字符串,不要注意图像)。

我不知道如何让 From 字符串出现

enter image description here



Best Answer-推荐答案


您可以在代码中为此使用 setCcRecipients:

关于iphone - 发件人地址的 MFMailComposeViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14155897/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4