Platforms to show: All Mac Windows Linux Cross-Platform
CNContactStoreMBS class
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
class | Contacts | MBS Mac64bit Plugin | 16.3 | ✅ Yes | ❌ No | ❌ No | ✅ Yes | Desktop & iOS |
The CNContactStore class provides ways to execute fetch and save requests. There are a few recommended ways you can implement these requests in your app to load contacts:
- Fetch only the contact properties that will be used.
- 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.
Your app must be code signed to see contacts.
Warning: Do not use in macOS 10.11 or earlier due to bugs, which have been fixed in macOS 10.12.
- 3 events
- event DidChange
- event enumerateContactsWithFetchRequest(contact as CNContactMBS, byref stop as boolean, tag as Variant)
- event requestAccessForEntityType(granted as boolean, error as NSErrorMBS, tag as Variant)
- 2 properties
- property currentHistoryToken as MemoryBlock
- property Handle as Integer
- 20 methods
- method allContacts(byref error as NSErrorMBS) as CNContactMBS()
- method Constructor
- method ContactsWithFetchRequest(fetchRequest as CNContactFetchRequestMBS, byref error as NSErrorMBS) as CNContactMBS()
- method containersMatchingPredicate(predicate as NSPredicateMBS, byref error as NSErrorMBS) as CNContainerMBS()
- method defaultContainerIdentifier as String
- method Destructor
- method enumerateContactsWithFetchRequest(fetchRequest as CNContactFetchRequestMBS, byref error as NSErrorMBS, tag as Variant = nil) as Boolean
- method enumeratorForChangeHistoryFetchRequest(request as CNChangeHistoryFetchRequestMBS, byref error as NSErrorMBS) as CNFetchResultMBS
- method enumeratorForContactFetchRequest(request as CNContactFetchRequestMBS, byref error as NSErrorMBS) as CNFetchResultMBS
- method executeSaveRequest(saveRequest as CNSaveRequestMBS, byref Error as NSErrorMBS) as Boolean
- method groupsByName(name as String, byref error as NSErrorMBS) as CNGroupMBS()
- method groupsForContact(contact as CNContactMBS, byref error as NSErrorMBS) as CNGroupMBS()
- method groupsMatchingPredicate(predicate as NSPredicateMBS, byref error as NSErrorMBS) as CNGroupMBS()
- method requestAccessForEntityType(entityType as Integer = 0, tag as Variant = nil)
- method unifiedContactsMatchingPredicate(predicate as NSPredicateMBS, byref error as NSErrorMBS) as CNContactMBS()
- method unifiedContactsMatchingPredicate(predicate as NSPredicateMBS, keysToFetch() as CNKeyDescriptorMBS, byref error as NSErrorMBS) as CNContactMBS()
- method unifiedContactWithIdentifier(identifier as string, byref error as NSErrorMBS) as CNContactMBS
- method unifiedContactWithIdentifier(identifier as string, keys() as CNKeyDescriptorMBS, byref error as NSErrorMBS) as CNContactMBS
- method unifiedMeContact(byref error as NSErrorMBS) as CNContactMBS
- method unifiedMeContactWithKeysToFetch(keys() as CNKeyDescriptorMBS, byref error as NSErrorMBS) as CNContactMBS
- 9 shared methods
- shared method AllFetchKeys as String()
- shared method authorizationStatusForEntityType(entityType as Integer = 0) as Integer
- shared method available as Boolean
- shared method CNContactStoreDidChangeNotification as String
- shared method CNErrorDomain as String
- shared method CNErrorUserInfoAffectedRecordIdentifiersKey as String
- shared method CNErrorUserInfoAffectedRecordsKey as String
- shared method CNErrorUserInfoKeyPathsKey as String
- shared method CNErrorUserInfoValidationErrorsKey as String
- 19 constants
Constants
Constant | Value | Description |
---|---|---|
CNAuthorizationStatusAuthorized | 3 |
One of the authorization status values the user can grant for an app to access the specified entity type.
The application is authorized to access contact data. |
CNAuthorizationStatusDenied | 2 |
One of the authorization status values the user can grant for an app to access the specified entity type.
The user explicitly denied access to contact data for the application. |
CNAuthorizationStatusNotDetermined | 0 |
One of the authorization status values the user can grant for an app to access the specified entity type.
The user has not yet made a choice regarding whether the application may access contact data. |
CNAuthorizationStatusRestricted | 1 |
One of the authorization status values the user can grant for an app to access the specified entity type.
The application is not authorized to access contact data. The user cannot change this application’s status, possibly due to active restrictions such as parental controls being in place. |
Contact Types
Constant | Value | Description |
---|---|---|
CNEntityTypeContacts | 0 |
Contacts |
Error Codes
Constant | Value | Description |
---|---|---|
CNErrorCodeAuthorizationDenied | 100 |
Authentication denied error. |
CNErrorCodeCommunicationError | 1 |
Communication error. |
CNErrorCodeContainmentCycle | 202 |
Code containment cycle error. |
CNErrorCodeContainmentScope | 203 |
Code containment scope error. |
CNErrorCodeDataAccessError | 2 |
Data access error. |
CNErrorCodeInsertedRecordAlreadyExists | 201 |
Record already exists. |
CNErrorCodeParentRecordDoesNotExist | 204 |
The contact does not exist error. |
CNErrorCodePolicyViolation | 500 |
Policy validation error. |
CNErrorCodePredicateInvalid | 400 |
Invalid predicate error. |
CNErrorCodeRecordDoesNotExist | 200 |
Record not found. |
CNErrorCodeRecordIdentifierInvalid | 205 |
Record identifier not valid. |
CNErrorCodeValidationConfigurationError | 302 |
Configuration validation error. |
CNErrorCodeValidationMultipleErrors | 300 |
Multiple validation error. |
CNErrorCodeValidationTypeMismatch | 301 |
Type mismatch validation error. |
This class has no sub classes.
Some examples using this class:
- /Mac64bit/Contacts/CNContactPicker Test
- /Mac64bit/Contacts/Contacts Display Person
- /Mac64bit/Contacts/Contacts History
- /Mac64bit/Contacts/Contacts Test
Blog Entries
- News from the MBS Xojo Plugins Version 22.0
- Contacts history for Xojo
- MBS Xojo Plugins, version 20.5pr1
- MBS Xojo Plugins, version 19.0pr8
- MBS Xojo Plugins, version 18.4pr7
- MBS Xojo Plugins, version 18.4pr5
- MBS Xojo Plugins, version 18.1pr1
Release notes
- Version 20.5
- Fixed exception raised by AllFetchKeys function in CNContactStoreMBS class.
- Version 19.0
- Added nil check of saveRequest parameter for CNContactStoreMBS.executeSaveRequest function.
- Version 18.4
- Added CNContactStoreMBS.CNErrorCodeRecordIdentifierInvalid constant.
- Added CNContactStoreMBS.groupsByName and CNContactStoreMBS.groupsForContact functions.
- Added more convenience functions for Contacts classes: allContacts, AllFetchKeys, unifiedContactsMatchingPredicate, unifiedContactWithIdentifier, unifiedMeContact for CNContactStoreMBS class and new CNContactFetchRequestMBS constructor.
- Version 18.1
- Fixed problem with notification receiving in CNContactStoreMBS.
The items on this page are in the following plugins: MBS Mac64bit Plugin.
CNContactRelationMBS - CNContactsUserDefaultsMBS