读取MFMailComposer中的收件人

时间:2011-04-20 16:52:07

标签: iphone ios email mfmailcomposer

我希望在用户按下发送邮件按钮后保存用户编写的邮件地址。但即使它可以设置为收件人,我也不知道如何从中读取(没有任何属性,或者更好的任何读取启用的属性,与toRecipient相关)。有什么建议吗?

2 个答案:

答案 0 :(得分:0)

我认为没有办法做到这一点。

答案 1 :(得分:0)

我找到了办法:

Code

MFMailComposeViewController *mViewController = [[MFMailComposeViewController alloc] init];

NSArray* listVues = [mViewController childViewControllers];
MFMailComposeViewController* mailContainer = [listVues objectAtIndex:0];
UIView* mailView = [[[mailContainer view] subviews] objectAtIndex:0];
UIScrollView* composer = [[mailView subviews] objectAtIndex:0];
UIView* composerFields = [[composer subviews] objectAtIndex:0];

for (UIView* item in [composerFields subviews])
{
    NSString* desc = [item description];
    if ([desc hasPrefix:@"<MFMailComposeRecipientView"] == YES)
    {
          for (UIView* subitem in [item subviews])
          {
                NSString* desc2 = [subitem description];
                if ([desc2 hasPrefix:@"<_MFMailRecipientTextField"] == YES)
                {
                        UITextView* txt = (UITextView*)subitem;
                }
           }
    }
    else
    if ([desc hasPrefix:@"MFComposeFromView"] == YES)
    {
                for (UIView* subitem in [item subviews])
                {
                    NSString* desc2 = [subitem description];
                    if ([desc2 hasPrefix:@"<UITextField"] == YES)
                    {
                        UITextView* txt = (UITextView*)subitem;
                    }
                }
    }
    else
    if ([desc hasPrefix:@"<MFComposeSubjectView"] == YES)
    {
          // ...
    }
    else
    if ([desc hasPrefix:@"<MFComposeMultiView"] == YES)
    {
          // ...
    }
}

根据任何需要更改四个“if([desc hasPrefix:@”...“] == YES)”内容中的一个。 您可以将[txt text]值保存到您自己的变量中。