【问题标题】:MFMailComposeViewController not populating recipients in ios 5MFMailComposeViewController 未在 ios 5 中填充收件人
【发布时间】:2014-01-10 09:01:30
【问题描述】:

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

【问题讨论】:

  • 能否在 sendEmailToContacts 方法上设置断点并检查 fList 是否包含指定的电子邮件列表,它可能是 nil 吗?
  • 适用于ios6及以上
  • 我检查了断点,flist 包含我上面发布的电子邮件,它适用于 ios7,我没有 ios6 sdk 所以不知道它是否适用
  • @Gamerlegend 检查 Bhavesh Lakum 的更新答案,我希望这次它会起作用

标签: ios iphone ios5 mfmailcomposeviewcontroller mfmailcomposer


【解决方案1】:

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

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

【讨论】:

  • 我尝试按照您的建议手动分配 fList 进行故障排除, NSArray *fList = [NSArray arrayWithObject: @"raja@apple.com"];但我仍然有同样的问题,它适用于 iOS7,但不适用于 iOS5
【解决方案2】:

试试这个。

        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];

【讨论】:

  • mailComposeViewController.mailComposeDelegate 中的 mailComposeViewController 是什么?
  • 不用写@Gamerlegend
  • @Gamerlegend mailComposeViewController.mailComposeDelegate 在 ios 5 中需要用于取消邮件视图,你能告诉我发生了什么错误,因为我测试了这段代码,它对我来说运行完美
  • 我省略了那行,这里的mailComposeViewController是什么,是指我当前的View控制器吗?
  • 不,在 ios 5 中按下取消按钮时关闭邮件发送窗口很有用
【解决方案3】:
-(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 之后设置,它将起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多