Class CNContactStore

  • All Implemented Interfaces:
    NSObject

    public class CNContactStore
    extends NSObject
    Provides methods to fetch and save contacts. The CNContactStore is a thread safe class that can fetch and save contacts, fetch and save groups, and fetch containers. [@note] Some good practices are: 1) Only fetch contact properties that will be used. 2) When fetching all contacts and caching the results, first fetch all contact identifiers only. Then fetch batches of detailed contacts by identifiers as you need them. 3) To aggregate several contact fetches collect a set of unique contact identifiers from the fetches. Then fetch batches of detailed contacts by identifiers. 4) When CNContactStoreDidChangeNotification is posted, if you cache any fetched contacts/groups/containers then they must be refetched and the old cached objects released.
    • Constructor Detail

      • CNContactStore

        protected CNContactStore​(org.moe.natj.general.Pointer peer)
    • Method Detail

      • accessInstanceVariablesDirectly

        public static boolean accessInstanceVariablesDirectly()
      • allocWithZone

        public static java.lang.Object allocWithZone​(org.moe.natj.general.ptr.VoidPtr zone)
      • authorizationStatusForEntityType

        public static long authorizationStatusForEntityType​(long entityType)
        Indicates the current authorization status to access contact data. Based upon the access, the application could display or hide its UI elements that would access any Contacts API. This method is thread safe.
        Returns:
        Returns the authorization status for the given entityType.
      • automaticallyNotifiesObserversForKey

        public static boolean automaticallyNotifiesObserversForKey​(java.lang.String key)
      • cancelPreviousPerformRequestsWithTarget

        public static void cancelPreviousPerformRequestsWithTarget​(java.lang.Object aTarget)
      • cancelPreviousPerformRequestsWithTargetSelectorObject

        public static void cancelPreviousPerformRequestsWithTargetSelectorObject​(java.lang.Object aTarget,
                                                                                 org.moe.natj.objc.SEL aSelector,
                                                                                 java.lang.Object anArgument)
      • classFallbacksForKeyedArchiver

        public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
      • classForKeyedUnarchiver

        public static org.moe.natj.objc.Class classForKeyedUnarchiver()
      • debugDescription_static

        public static java.lang.String debugDescription_static()
      • description_static

        public static java.lang.String description_static()
      • hash_static

        public static long hash_static()
      • instanceMethodSignatureForSelector

        public static NSMethodSignature instanceMethodSignatureForSelector​(org.moe.natj.objc.SEL aSelector)
      • instancesRespondToSelector

        public static boolean instancesRespondToSelector​(org.moe.natj.objc.SEL aSelector)
      • isSubclassOfClass

        public static boolean isSubclassOfClass​(org.moe.natj.objc.Class aClass)
      • keyPathsForValuesAffectingValueForKey

        public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey​(java.lang.String key)
      • new_objc

        public static java.lang.Object new_objc()
      • resolveClassMethod

        public static boolean resolveClassMethod​(org.moe.natj.objc.SEL sel)
      • resolveInstanceMethod

        public static boolean resolveInstanceMethod​(org.moe.natj.objc.SEL sel)
      • setVersion_static

        public static void setVersion_static​(long aVersion)
      • superclass_static

        public static org.moe.natj.objc.Class superclass_static()
      • version_static

        public static long version_static()
      • containersMatchingPredicateError

        public NSArray<? extends CNContainer> containersMatchingPredicateError​(NSPredicate predicate,
                                                                               org.moe.natj.general.ptr.Ptr<NSError> error)
        Fetch all containers matching a given predicate. Use only predicates from CNContainer+Predicates.h. Compound predicates are not supported.
        Parameters:
        predicate - The predicate to match against. Set to nil to match all containers.
        error - If an error occurs, contains error information.
        Returns:
        An array of CNContainer objects matching the predicate. If no matches are found, an empty array is returned. If an error occurs, nil is returned.
      • defaultContainerIdentifier

        public java.lang.String defaultContainerIdentifier()
        The identifier of the default container. This identifier can be used to fetch the default container.
        Returns:
        The identifier of the default container. If the caller lacks Contacts authorization or an error occurs, nil is returned.
      • enumerateContactsWithFetchRequestErrorUsingBlock

        public boolean enumerateContactsWithFetchRequestErrorUsingBlock​(CNContactFetchRequest fetchRequest,
                                                                        org.moe.natj.general.ptr.Ptr<NSError> error,
                                                                        CNContactStore.Block_enumerateContactsWithFetchRequestErrorUsingBlock block)
        Enumerates all contacts matching a contact fetch request. This method will wait until the enumeration is finished. If there are no results, the block is not called and YES is returned.
        Parameters:
        fetchRequest - The contact fetch request that specifies the search criteria.
        error - If an error occurs, contains error information.
        block - Called for each matching contact. Set *stop to YES to stop the enumeration.
        Returns:
        YES if successful, otherwise NO.
      • executeSaveRequestError

        public boolean executeSaveRequestError​(CNSaveRequest saveRequest,
                                               org.moe.natj.general.ptr.Ptr<NSError> error)
        Executes a save request. Do not access objects when save request is executing. A save request with contacts may modify the contacts while executing. A save request only applies the changes to the objects. If there are overlapping changes with multiple, concurrent CNSaveRequests then the last saved change wins.
        Parameters:
        saveRequest - Save request to execute.
        error - If an error occurs, contains error information.
        Returns:
        YES if successful, otherwise NO.
      • groupsMatchingPredicateError

        public NSArray<? extends CNGroup> groupsMatchingPredicateError​(NSPredicate predicate,
                                                                       org.moe.natj.general.ptr.Ptr<NSError> error)
        Fetch all groups matching a given predicate. Use only predicates from CNGroup+Predicates.h. Compound predicates are not supported.
        Parameters:
        predicate - The predicate to match against. Set to nil to match all groups.
        error - If an error occurs, contains error information.
        Returns:
        An array of CNGroup objects matching the predicate. If no matches are found, an empty array is returned. If an error occurs, nil is returned.
      • requestAccessForEntityTypeCompletionHandler

        public void requestAccessForEntityTypeCompletionHandler​(long entityType,
                                                                CNContactStore.Block_requestAccessForEntityTypeCompletionHandler completionHandler)
        Request access to the user's contacts. Users are able to grant or deny access to contact data on a per-application basis. To request access to contact data, call requestAccessForEntityType:completionHandler:. This will not block the application while the user is being asked to grant or deny access. The user will only be prompted the first time access is requested; any subsequent CNContactStore calls will use the existing permissions. The completion handler is called on an arbitrary queue. [@note] Recommended to use CNContactStore instance methods in this completion handler instead of the UI main thread. This method is optional when CNContactStore is used on a background thread. If it is not used in that case, CNContactStore will block if the user is asked to grant or deny access.
        Parameters:
        entityType - Set to CNEntityTypeContacts.
        completionHandler - This block is called upon completion. If the user grants access then granted is YES and error is nil. Otherwise granted is NO with an error.
      • unifiedContactWithIdentifierKeysToFetchError

        public CNContact unifiedContactWithIdentifierKeysToFetchError​(java.lang.String identifier,
                                                                      NSArray<?> keys,
                                                                      org.moe.natj.general.ptr.Ptr<NSError> error)
        Fetch a unified contact with a given identifier. Due to unification the returned contact may have a different identifier. To fetch a batch of contacts by identifiers use [CNContact predicateForContactsWithIdentifiers:].
        Parameters:
        identifier - The identifier of the contact to fetch.
        keys - The properties to fetch into the returned CNContact object. Should only fetch the properties that will be used. Can combine contact keys and contact key descriptors.
        error - If an error occurs, contains error information.
        Returns:
        The unified contact matching or linked to the identifier. If no contact with the given identifier is found, nil is returned and error is set to CNErrorCodeRecordDoesNotExist.
      • unifiedContactsMatchingPredicateKeysToFetchError

        public NSArray<? extends CNContact> unifiedContactsMatchingPredicateKeysToFetchError​(NSPredicate predicate,
                                                                                             NSArray<?> keys,
                                                                                             org.moe.natj.general.ptr.Ptr<NSError> error)
        Fetch all unified contacts matching a given predicate. Use only predicates from CNContact+Predicates.h. Compound predicates are not supported. Due to unification the returned contacts may have a different identifier. [@note] To fetch all contacts use enumerateContactsWithFetchRequest:error:usingBlock:.
        Parameters:
        predicate - The predicate to match against.
        keys - The properties to fetch into the returned CNContact objects. Should only fetch the properties that will be used. Can combine contact keys and contact key descriptors.
        error - If an error occurs, contains error information.
        Returns:
        An array of CNContact objects matching the predicate. If no matches are found, an empty array is returned. If an error occurs, nil is returned.
      • currentHistoryToken

        public NSData currentHistoryToken()
        The current history token. Retrieve the current history token. If you are fetching contacts or change history events, you should use the token on the @c CNFetchResult instead.
      • enumeratorForChangeHistoryFetchRequestError

        public CNFetchResult<NSEnumerator<CNChangeHistoryEvent>> enumeratorForChangeHistoryFetchRequestError​(CNChangeHistoryFetchRequest request,
                                                                                                             org.moe.natj.general.ptr.Ptr<NSError> error)
        Enumerate a change history fetch request. Executes the given fetch request and returns an enumerator for the results. This may prevent all events from being loaded into memory at once. An exception may be thrown if an error occurs during enumeration.
        Parameters:
        request - A description of the events to fetch.
        error - If the fetch fails, contains an @c NSError object with more information.
        Returns:
        An enumerator of the events matching the result, or @c nil if there was an error.
      • enumeratorForContactFetchRequestError

        public CNFetchResult<NSEnumerator<CNContact>> enumeratorForContactFetchRequestError​(CNContactFetchRequest request,
                                                                                            org.moe.natj.general.ptr.Ptr<NSError> error)
        Enumerate a contact fetch request. Executes the given fetch request and returns an enumerator for the results. This may prevent all records from being loaded into memory at once. An exception may be thrown if an error occurs during enumeration.
        Parameters:
        request - A description of the records to fetch.
        error - If the fetch fails, contains an @c NSError object with more information.
        Returns:
        An enumerator of the records matching the result, or @c nil if there was an error.