How To Get Account Name From Contact Framework

后端 未结 1 777
暖寄归人
暖寄归人 2021-01-27 09:22

We know that contacts in iOS can be synced from Google, iCloud and Phone. Well, we can fetch a bunch of Contacts using Contacts.fram

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 10:08

    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
                        }
    
                    }
                }
            }
                }
            }];
    }
    

    0 讨论(0)
提交回复
热议问题