MFMailComposeViewController不填充ios 5中的收件人

时间:2014-01-10 09:01:30

标签: ios iphone ios5 mfmailcomposeviewcontroller mfmailcomposer

我尝试将邮件发送到我从数据库收到的电子邮件数组列表,当我发送收件人列表时,会填充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"
)

3 个答案:

答案 0 :(得分:0)

收件人应该是不可变数组。检查你的数组类型

  NSArray *usersTo = [NSArray arrayWithObject: @"raja@apple.com"];
    [mailComposer setToRecipients:usersTo];

答案 1 :(得分: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];

答案 2 :(得分: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之后设置,它将起作用。