Class

CNContactStore

The object that fetches and saves contacts, groups, and containers from the user's contacts database.

Declaration

@interface CNContactStore : NSObject

Overview

The CNContactStore object represents the user's contacts store database, and you use it to fetch information from that database and save changes back to it. There are a few recommended ways you can implement fetch and save requests in your app:

  • Fetch only the properties that you need for contacts.

  • When fetching all contacts and caching the results, first fetch all contacts identifiers, then fetch batches of detailed contacts by identifiers as required.

  • To aggregate several contacts fetches, first collect a set of unique identifiers from the fetches. Then fetch batches of detailed contacts by those unique identifiers.

  • If you cache the fetched contacts, groups, or containers, you need to refetch these objects (and release the old cached objects) when CNContactStoreDidChangeNotification is posted.

Because CNContactStore fetch methods perform I/O, it’s recommended that you avoid using the main thread to execute fetches.

Topics

Requesting Access to the User's Contacts

- requestAccessForEntityType:completionHandler:

Requests access to the user's contacts.

+ authorizationStatusForEntityType:

Returns the current authorization status to access the contact data.

CNAuthorizationStatus

An authorization status the user can grant for an app to access the specified entity type.

CNEntityType

The entities the user can grant access to.

Fetching Contacts

- enumerateContactsWithFetchRequest:error:usingBlock:

Returns a Boolean value that indicates whether the enumeration of all contacts matching a contact fetch request executed successfully.

- unifiedMeContactWithKeysToFetch:error:

Fetches the unified contact that is the "me" card.

- unifiedContactWithIdentifier:keysToFetch:error:

Fetches a unified contact for the specified contact identifier.

- unifiedContactsMatchingPredicate:keysToFetch:error:

Fetches all unified contacts matching the specified predicate.

Fetching Groups and Containers

- defaultContainerIdentifier

Returns the identifier of the default container.

- groupsMatchingPredicate:error:

Fetches all groups matching the specified predicate.

- containersMatchingPredicate:error:

Fetches all containers matching the specified predicate.

Saving Changes

- executeSaveRequest:error:

Executes a save request and returns success or failure.

Responding to Contact Store Changes

CNContactStoreDidChangeNotification

Posted when changes occur to the contact store.

Relationships

Inherits From