1

我已经编写代码以在单击按钮时发送邮件。但我以编程方式拥有电子邮件 ID。我有这样的输出。

email@gmail.com 发送邮件按钮

现在,当我单击发送 MailButton 时,它会打开 MFMailComposeViewController 但字段为空。这里的 email@gmail.com 是动态更改的,它不是固定的。

我的代码是

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

if([MFMailComposeViewController canSendMail])
{
    NSString *emailBody;
    emailBody=self.shareString;
    //NSLog(@"EMail Body ---- %@",emailBody);

    [picker setMessageBody:emailBody isHTML:YES];
    [picker becomeFirstResponder];

    [self presentModalViewController:picker animated:YES];
}

这里需要改变什么?

4

2 回答 2

1

使用以下代码:

NSArray *tempArray = [[NSArray alloc] initWithObjects:@"abc@gmail.com", nil];
[picker setToRecipients:tempArray];

它对我来说工作正常。

谢谢,赫芒。

于 2013-01-05T07:45:11.910 回答
0

那么你需要首先为此创建一个数组。

-(void)displayComposerSheetEmailUs{

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"Hello from the App!"];

    // Set up recipients
             NSArray *toRecipients = [NSArray arrayWithObject:@"abc@gmail.com"]; 
             [picker setToRecipients:toRecipients];

    // Fill out the email body text
        NSString *emailBody = @"It is raining in sunny California!";
        [picker setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:picker animated:YES];

}
于 2013-01-05T07:49:07.247 回答