如何从联系人框架获取帐户名称
我们知道iOS中的联系人可以通过Google
, iCloud
和Phone
同步。 那么,我们可以使用Contacts.framework
获取一堆Contacts.framework
,但我想知道它属于哪个帐户。
我的意思是,我需要区分电子邮件和电话同步联系人。 有没有办法做到这一点?
我正在使用contact framework
。 我使用CNContainer
获取标识符,但是如何获取存储联系人的帐户名称以及如何从该帐户获取联系人?
你可以请尝试提取所有的容器,然后你可以根据容器名称分组这些联系人
-(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 } } } } } }]; }