获取 MFMailComposeViewController 中的收件人列表

发布于 2024-12-28 10:39:28 字数 100 浏览 0 评论 0原文

我在我的应用程序中使用 MFMailcomposerViewController。一切工作正常,除了我需要有没有。收件人以及用户发送邮件的收件人列表。 有关此问题的任何帮助或解决方案..

I am using MFMailcomposerViewController in my App. Everything is working fine, except that I am in need to Have the no. of recipients and the list of recipients the user is sending to.
Any help or solution regarding this issue..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陪我终i 2025-01-04 10:39:28

我没有标准方法来执行此操作,委托方法 mailComposeController:didFinishWithResult:error: 在 Compose 视图控制器被关闭后为您提供对它的引用,但是 上没有访问器>MFMailComposeViewController 您可以使用它来获取收件人计数

解决方法是检查视图控制器的子视图,找到用于保存收件人的文本字段并获取文本:请参阅 此处

I dont there is a standard way to do this, the delegate method mailComposeController:didFinishWithResult:error: gives you a reference to the composer view controller after it has been dismissed, but there are no accessors on MFMailComposeViewController which you could use to get the recipient count

A workaround would be to examine the subviews of the view controller, find the text field which was used to hold the recipients and get the text: see here

不即不离 2025-01-04 10:39:28

最后我得到了答案并想分享它......我从[博客]获得了很大的帮助:http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html

for (int x=0; x<[emailArray count]-1; x++) {
NSLog(@"%d). %@",x+1,[emailArray objectAtIndex:x]);
NSString *element = [emailArray objectAtIndex:x];
NSArray *arr = [element componentsSeparatedByString:@" & "];
if ([arr count]==1) {
    ++emailCount;
}
else{
    int more = [[[arr objectAtIndex:1] substringToIndex:1] intValue];
    emailCount+=(more+1);
}
}
 - (NSString *)findEmailAddresses:(UIView *)view depth:(NSInteger)count
{
NSString *eAddress = nil;
if (!view)
    return eAddress;
NSMutableString *tabString = [NSMutableString stringWithCapacity:count];
for (int i = 0; i < count; i++)
    [tabString appendString:@"-- "];
NSLog(@"%@%@", tabString, view);
if ([view isKindOfClass:[UITextField class]])
{
    // MAGIC: debugger shows email address(es) in first textField
    // but only if it's about max 35 characters
    if (((UITextField *)view).text)
    {
        eAddress = [NSString stringWithString:((UITextField *)view).text];
        NSLog(@"FOUND UITextField: %@", eAddress ? eAddress : @"");
        [emailArray addObject:eAddress];
    }
}
NSArray *subviews = [view subviews];
if (subviews) {
    for (UIView *view in subviews)
    {
        NSString *s = [self findEmailAddresses:view depth:count+1];
        if (s) eAddress = s;
    }
}
return eAddress;
}

Finally I got the Answer and wanted to share it... I took a great help from [blog]: http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html

for (int x=0; x<[emailArray count]-1; x++) {
NSLog(@"%d). %@",x+1,[emailArray objectAtIndex:x]);
NSString *element = [emailArray objectAtIndex:x];
NSArray *arr = [element componentsSeparatedByString:@" & "];
if ([arr count]==1) {
    ++emailCount;
}
else{
    int more = [[[arr objectAtIndex:1] substringToIndex:1] intValue];
    emailCount+=(more+1);
}
}
 - (NSString *)findEmailAddresses:(UIView *)view depth:(NSInteger)count
{
NSString *eAddress = nil;
if (!view)
    return eAddress;
NSMutableString *tabString = [NSMutableString stringWithCapacity:count];
for (int i = 0; i < count; i++)
    [tabString appendString:@"-- "];
NSLog(@"%@%@", tabString, view);
if ([view isKindOfClass:[UITextField class]])
{
    // MAGIC: debugger shows email address(es) in first textField
    // but only if it's about max 35 characters
    if (((UITextField *)view).text)
    {
        eAddress = [NSString stringWithString:((UITextField *)view).text];
        NSLog(@"FOUND UITextField: %@", eAddress ? eAddress : @"");
        [emailArray addObject:eAddress];
    }
}
NSArray *subviews = [view subviews];
if (subviews) {
    for (UIView *view in subviews)
    {
        NSString *s = [self findEmailAddresses:view depth:count+1];
        if (s) eAddress = s;
    }
}
return eAddress;
}
娇女薄笑 2025-01-04 10:39:28

从 iOS 6 开始,无法执行此操作,因为邮件撰写现在是通过对远程进程 (MailCompositionService) 的 XPC 服务调用来完成。这里有一个很好的解释: http://oleb .net/blog/2012/10/remote-view-controllers-in-ios-6/。视图层次结构中的最低级别现在是与远程进程交互的 _UIRemoteView。博客文章中的代码 http://jomnius.blogspot。 com/2011/02/how-to-find-mfmailcomposeviewcontroller.html 现在将始终返回 nil。

There is no way to do this as of iOS 6 as mail composition is now done through an XPC service call to a remote process (MailCompositionService). There is a great explanation here: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/. The lowest level in the view hierarchy is now an _UIRemoteView which interfaces to the remote process. The code from the blog post at http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html will now alway return nil.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文