Ejemplo n.º 1
0
        /// <summary>
        /// Returns a Boolean value that indicates whether the enumeration of
        /// all contacts matching a contact fetch request executed successfully.
        /// </summary>
        /// <returns><c>true</c>, if contacts with fetch request was enumerated, <c>false</c> otherwise.</returns>
        /// <param name="fetchRequest">Fetch request.</param>
        /// <param name="error">Error.</param>
        /// <param name="block">Block.</param>
        public bool EnumerateContactsWithFetchRequest(CNContactFetchRequest fetchRequest, out NSError error, EnumerateContactsWithFetchRequestBlock block)
        {
            Util.NullArgumentTest(fetchRequest);
            Util.NullArgumentTest(block);

            IntPtr errorPtr = new IntPtr();
            bool   success  = C.CNContactStore_enumerateContactsWithFetchRequest(
                SelfPtr(),
                fetchRequest.ToPointer(),
                ref errorPtr,
                InternalEnumerateContactsBlock,
                PInvokeCallbackUtil.ToIntPtr((CNContact contact) =>
            {
                bool shouldStop;
                block(contact, out shouldStop);
                return(shouldStop);
            }));

            error = null;
            if (PInvokeUtil.IsNotNull(errorPtr))
            {
                error = new NSError(errorPtr);
                CFFunctions.CFRelease(errorPtr);     // balance out ref count of a pointer returned directly from native side.
            }

            return(success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The designated initializer for a fetch request that uses the specified keys.
        /// </summary>
        /// <returns>The with keys to fetch.</returns>
        /// <param name="keysToFetch">Keys to fetch.</param>
        public static CNContactFetchRequest InitWithKeysToFetch(NSArray <NSString> keysToFetch)
        {
            if (keysToFetch == null)
            {
                return(null);
            }

            // This will automatically call alloc on native side before calling the init method.
            var ptr = C.CNContactFetchRequest_initWithKeysToFetch(keysToFetch.ToPointer());
            CNContactFetchRequest request = null;

            if (PInvokeUtil.IsNotNull(ptr))
            {
                request = new CNContactFetchRequest(ptr);
                CFFunctions.CFRelease(ptr);
            }

            return(request);
        }