2

我正在尝试将邮件发送到我从数据库接收的电子邮件数组列表,当我发送收件人列表时会被填充,iOS 7但当我尝试在iOS 5收件人列表中时不会被填充。任何想法为什么?这是我的邮件功能

-(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
{
    if([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
        mailComposer.view.tag=tag;
        NSString *htmlBody =[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",_currentAdd.contentUrl,addtext];
        [mailComposer setMessageBody:htmlBody isHTML:YES];
        [mailComposer setSubject:_currentMail.subject];
        mailComposer.mailComposeDelegate = self;
        [mailComposer setToRecipients:fList];
        [self presentViewController:mailComposer animated:YES completion:nil];
    }
    else
    {
       NSLog(@"Device is unable to send email in its current state.");
    }
}

我的fList(收件人列表)是一个NSArray,这是我的 fList 的示例输出

(
    "john@gmail.com",
    "mary@gmail.com",
    "akhil@gmail.com",
    "tester@gmail.com"
)
4

3 回答 3

0

收件人应为不可变数组。检查您的阵列类型

  NSArray *usersTo = [NSArray arrayWithObject: @"raja@apple.com"];
    [mailComposer setToRecipients:usersTo];
于 2014-01-10T09:51:55.857 回答
0

试试这个。

        NSArray *fList = [NSArray arrayWithObjects:@"raja@apple.com",@"john@gmail.com",@"mary@gmail.com",@"akhil@gmail.com",@"tester@gmail.com", nil];

        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
        mailComposer.view.tag=tag;
        NSString *htmlBody =[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",_currentAdd.contentUrl,addtext];
        [mailComposer setMessageBody:htmlBody isHTML:YES];
        mailComposer.mailComposeDelegate = self;
        [mailComposer setSubject:_currentMail.subject];
        mailComposer.delegate = self;
        [mailComposer setToRecipients:fList];
        [self presentViewController:mailComposer animated:YES completion:nil];
于 2014-01-10T10:12:00.923 回答
0
-(void)sendEmailToContacts:(NSArray *)fList withText:(NSString *)emailText withTag:(NSInteger )tag
{
    if([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
        //mailComposer.view.tag=tag;
        NSString *htmlBody =[NSString stringWithFormat:@"<a href=\"%@\">%@</a>",_currentAdd.contentUrl,addtext];
        [mailComposer setMessageBody:htmlBody isHTML:YES];
        [mailComposer setSubject:_currentMail.subject];
        mailComposer.mailComposeDelegate = self;
        [mailComposer setToRecipients:fList];
        [self presentViewController:mailComposer animated:YES completion:nil];
    }
    else
    {
       NSLog(@"Device is unable to send email in its current state.");
    }
}

显然,如果我尝试在 setToRecipients 行之前设置标签,则问题出在设置标签上,它不会在 iOS 5 中显示收件人列表,如果在 setToRecipients 之后注释掉或设置设置标签行,它将起作用。

于 2014-01-14T04:42:07.160 回答