我们知道iOS中的联系人可以从Google
, iCloud
and Phone
。好吧,我们可以使用以下方法获取一堆联系人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
}
}
}
}
}
}];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)