How To Get Account Name From Contact 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?

  • How can I simulate the touch events by IOHIDEvent?
  • Using Tint color on UIImageView
  • Concatenating transform animations in Swift 3?? What is wrong?
  • Azure notification hubs - how to set multiple apps on the same hub
  • Added table view cells follow 1 custom style?
  • accessoryButtonTappedForRowWithIndexPath: not getting called.
  • 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?

    Solutions Collect From Internet About “How To Get Account Name From Contact Framework”

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