How can I determine that CNContact is is favorites

2019-08-02 16:47发布

This question already has an answer here:

My iOS application fetches contacts from device using code

[[CNContactStore new] requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) {
  if (granted) {
    NSArray *keys = @[CNContactNamePrefixKey,
                      CNContactGivenNameKey,
                      CNContactMiddleNameKey,
                      CNContactFamilyNameKey,
                      // ...
    NSString *containerId = store.defaultContainerIdentifier;
    NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
    NSArray *cnContacts = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
    for (CNContact *contact in cnContacts) {
      // contacts fetching
    }
  }
}];

Has CNContact class some value means that contact is in favorites on device (in Phone application)? I didn't found such key in CNContact keys.

Or maybe predicate contains keys that I needs?

1条回答
Root(大扎)
2楼-- · 2019-08-02 17:32

Filip Radelic answered same question:

Favorites are stored inside Phone.app, not inside the Address Book database itself. You can't access other app's sandbox on a non-jailbroken iPhone, so unfortunately the answer is no.

Also, it would be pretty bad for privacy if any app could see your favorite contacts. It's already bad that it can access entire address book without asking you.

查看更多
登录 后发表回答