如何从Contact Framework获取帐户名称 [英] How To Get Account Name From Contact Framework

查看:194
本文介绍了如何从Contact Framework获取帐户名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道iOS中的联系人可以从 Google iCloud 手机同步。好吧,我们可以使用 Contacts.framework 获取一堆联系人,但我想知道它属于哪个帐户。

We know that contacts in iOS can be synced from Google, iCloud and Phone. Well, we can fetch a bunch of Contacts using Contacts.framework, but I want to know which account it belongs to.

我的意思是,我需要区分电子邮件和电话同步的联系人。有没有办法这样做?

I mean, I need to differentiate Email and Phone synced contacts. Is there any way to do so?

我正在使用联系框架。我使用 CNContainer 获取标识符,但是如何获取存储联系人的帐户名以及如何从该帐户获取该联系人?

I am using contact framework. I am getting identifier by using CNContainer, but how to get account name in which contacts are stored and also how fetch that contact’s from that account?

推荐答案

您可以尝试抓取所有容器,然后根据容器名称对这些联系人进行分组

Can you please try fetching All container's and then you can Group those contacts according to the container name

  -(void)fetchContacts
    {
   CNContactStore *store = [[CNContactStore alloc] init];    
   [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
  if (granted == YES)
  {
        NSArray * contactContainerArray =  [store containersMatchingPredicate:nil error:nil];
        for(CNContainer * container in contactContainerArray) {
            NSLog(@"Container name == %@ ",container.name);
            NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:container.identifier];
            NSError *error;
            NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
            if (error)
            {
                NSLog(@"error fetching contacts %@", error);
            }
            else
            {
                for (CNContact *contact in cnContacts) {
                    NSMutableArray *contactNumbersArray = [[NSMutableArray alloc]init];
                    //  contact.givenName;
                    // contact.familyName;

                    for (CNLabeledValue *label in contact.phoneNumbers) {
                       // [label.value stringValue]; Phone Number
                    }

                }
            }
        }
            }
        }];
}

这篇关于如何从Contact Framework获取帐户名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆