예제 #1
0
        private static void InternalDidRequestMatchWithOtherPlayersCallback(IntPtr listenerPtr, IntPtr player, IntPtr playersToInvite)
        {
            var forwarder = FromPointer(listenerPtr);

            if (forwarder != null && forwarder.ListenerCount > 0)
            {
                // GKPlayer.
                GKPlayer gkPlayer = InteropObjectFactory <GKPlayer> .FromPointer(player, ptr => new GKPlayer(ptr));

                // GKPlayer[].
                GKPlayer[] gkPlayersToInvite = null;

                if (PInvokeUtil.IsNotNull(playersToInvite))
                {
                    // Creating a one-time usage NSArray binder, no need to use the factory.
                    using (var nsArray = new NSArray <GKPlayer>(playersToInvite))
                    {
                        gkPlayersToInvite = nsArray.ToArray(ptr => InteropObjectFactory <GKPlayer> .FromPointer(ptr, p => new GKPlayer(p)));
                    }
                }

                // Invoke consumer delegates.
                forwarder.InvokeOnAllListeners(l => l.PlayerDidRequestMatchWithOtherPlayers(gkPlayer, gkPlayersToInvite));
            }
        }
예제 #2
0
        /// <summary>
        /// Fetches a unified contact for the specified contact identifier.
        /// </summary>
        /// <returns>The contact with identifier.</returns>
        /// <param name="identifier">Identifier.</param>
        /// <param name="keys">Keys.</param>
        /// <param name="error">Error.</param>
        public CNContact UnifiedContactWithIdentifier(NSString identifier, NSArray <NSString> keys, out NSError error)
        {
            Util.NullArgumentTest(identifier);
            Util.NullArgumentTest(keys);

            IntPtr errorPtr   = new IntPtr();
            var    contactPtr = C.CNContactStore_unifiedContactWithIdentifier(
                SelfPtr(),
                identifier.ToPointer(),
                keys.ToPointer(),
                ref errorPtr);

            error = null;
            if (PInvokeUtil.IsNotNull(errorPtr))
            {
                error = new NSError(errorPtr);
                CFFunctions.CFRelease(errorPtr);
            }

            CNContact contact = null;

            if (PInvokeUtil.IsNotNull(contactPtr))
            {
                contact = new CNContact(contactPtr);
                CFFunctions.CFRelease(contactPtr);
            }

            return(contact);
        }
예제 #3
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);
        }
예제 #4
0
        private static void InternalMultipleMatchesCallback(IntPtr matches, IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            GKTurnBasedMatch[] gkMatches = null;

            if (PInvokeUtil.IsNotNull(matches))
            {
                // Creating a one-time usage NSArray binder, no need to use the factory.
                using (var nsArray = new NSArray <GKTurnBasedMatch>(matches))
                {
                    gkMatches = nsArray.ToArray(ptr => InteropObjectFactory <GKTurnBasedMatch> .FromPointer(ptr, p => new GKTurnBasedMatch(p)));
                }
            }

            // A new NSError object is always created on native side, so no need
            // to check the binder pool for reusing an existing one.
            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            // Invoke consumer callback.
            PInvokeCallbackUtil.PerformInternalCallback(
                "GKTurnBasedMatch#InternalMultipleMatchesCallback",
                PInvokeCallbackUtil.Type.Temporary,
                gkMatches, nsError, secondaryCallback);
        }
예제 #5
0
        /// <summary>
        /// Fetches all unified contacts matching the specified predicate.
        /// </summary>
        /// <returns>The contacts matching predicate.</returns>
        /// <param name="predicate">Predicate.</param>
        /// <param name="keys">Keys.</param>
        /// <param name="error">Error.</param>
        public NSArray <CNContact> UnifiedContactsMatchingPredicate(NSPredicate predicate, NSArray <NSString> keys, out NSError error)
        {
            Util.NullArgumentTest(predicate);
            Util.NullArgumentTest(keys);

            IntPtr errorPtr    = new IntPtr();
            var    contactsPtr = C.CNContactStore_unifiedContactsMatchingPredicate(
                SelfPtr(),
                predicate.ToPointer(),
                keys.ToPointer(),
                ref errorPtr);

            error = null;
            if (PInvokeUtil.IsNotNull(errorPtr))
            {
                error = new NSError(errorPtr);
                CFFunctions.CFRelease(errorPtr);
            }

            NSArray <CNContact> contacts = null;

            if (PInvokeUtil.IsNotNull(contactsPtr))
            {
                contacts = new NSArray <CNContact>(contactsPtr);
                CFFunctions.CFRelease(contactsPtr);
            }

            return(contacts);
        }
예제 #6
0
        private static void InternalLoadMatchDataCallback(IntPtr matchData, IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            byte[] data = null;

            if (PInvokeUtil.IsNotNull(matchData))
            {
                // Creating a one-time usage NSData binder, so no need to use the factory.
                using (var nsData = new NSData(matchData))
                {
                    var length = nsData.Length;
                    if (length > 0)
                    {
                        data = nsData.GetBytes(length);
                    }
                }
            }

            // A new NSError object is always created on native side, so no need
            // to check the binder pool for reusing an existing one.
            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKTurnBasedMatch#InternalLoadMatchDataCallback",
                PInvokeCallbackUtil.Type.Temporary,
                data, nsError, secondaryCallback);
        }
예제 #7
0
파일: NSPredicate.cs 프로젝트: artemy0/Quiz
        /// <summary>
        /// Creates and returns a predicate that always evaluates to a given Boolean value.
        /// </summary>
        /// <returns>The with value.</returns>
        /// <param name="value">If set to <c>true</c> value.</param>
        public static NSPredicate PredicateWithValue(bool value)
        {
            NSPredicate predicate = null;
            var         ptr       = C.NSPredicate_predicateWithValue(value);

            if (PInvokeUtil.IsNotNull(ptr))
            {
                predicate = new NSPredicate(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(predicate);
        }
예제 #8
0
파일: CNContact.cs 프로젝트: artemy0/Quiz
        /// <summary>
        /// Returns a new instance that’s a mutable copy of the receiver.
        /// </summary>
        /// <returns>The copy.</returns>
        public CNMutableContact MutableCopy()
        {
            CNMutableContact mutCopy = null;
            var ptr = C.CNContact_mutableCopy(SelfPtr());

            if (PInvokeUtil.IsNotNull(ptr))
            {
                mutCopy = new CNMutableContact(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(mutCopy);
        }
예제 #9
0
        /// <summary>
        /// Returns the required key descriptor for the specified formatting style of the contact.
        /// </summary>
        /// <returns>The for required keys for style.</returns>
        /// <param name="style">Style.</param>
        public static CNKeyDescriptor DescriptorForRequiredKeysForStyle(CNContactFormatterStyle style)
        {
            InternalCNKeyDescriptor keyDesc = null;
            var ptr = C.CNContactFormatter_descriptorForRequiredKeysForStyle(style);

            if (PInvokeUtil.IsNotNull(ptr))
            {
                keyDesc = new InternalCNKeyDescriptor(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(keyDesc);
        }
예제 #10
0
파일: NSData.cs 프로젝트: artemy0/Quiz
 /// <summary>
 /// Creates a NSData object from a pointer and release that pointer.
 /// </summary>
 /// <returns>The NSData object.</returns>
 /// <param name="pointer">Pointer.</param>
 private static NSData FromPointer(IntPtr pointer)
 {
     if (PInvokeUtil.IsNotNull(pointer))
     {
         var obj = new NSData(pointer);
         CoreFoundation.CFFunctions.CFRelease(pointer);
         return(obj);
     }
     else
     {
         return(null);
     }
 }
예제 #11
0
        /// <summary>
        /// Get the contact property value.
        /// </summary>
        /// <param name="constructor">Constructor to create object of type <see cref="T"/>.</param>
        public T GetValue(Func <IntPtr, T> constructor)
        {
            if (mValue == null)
            {
                var ptr = C.CNLabeledValue_value(SelfPtr());

                if (PInvokeUtil.IsNotNull(ptr))
                {
                    mValue = constructor(ptr);
                    CFFunctions.CFRelease(ptr);
                }
            }
            return(mValue);
        }
예제 #12
0
        private static void InternalErrorOnlyCallback(IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKTurnBasedMatch#InternalErrorOnlyCallback",
                PInvokeCallbackUtil.Type.Temporary,
                nsError, secondaryCallback);
        }
예제 #13
0
        private static void IntErrorCallback(
            int intArg, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKMatchmaker#IntErrorCallback",
                PInvokeCallbackUtil.Type.Temporary,
                intArg, error, secondaryCallback);
        }
예제 #14
0
        /// <summary>
        /// Executes a save request and returns success or failure.
        /// </summary>
        /// <returns><c>true</c>, if save request was executed, <c>false</c> otherwise.</returns>
        /// <param name="saveRequest">Save request.</param>
        /// <param name="error">Error.</param>
        public bool ExecuteSaveRequest(CNSaveRequest saveRequest, out NSError error)
        {
            Util.NullArgumentTest(saveRequest);

            IntPtr errorPtr = new IntPtr();
            bool   success  = C.CNContactStore_executeSaveRequest(SelfPtr(), saveRequest.ToPointer(), ref errorPtr);

            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);
        }
예제 #15
0
 /// <summary>
 /// Creates a UIImage object from a pointer and release the pointer if required.
 /// </summary>
 /// <returns>The UIImage object.</returns>
 /// <param name="pointer">Pointer.</param>
 /// <param name="releasePointer">If set to <c>true</c> release pointer.</param>
 internal static UIImage FromPointer(IntPtr pointer, bool releasePointer)
 {
     if (PInvokeUtil.IsNotNull(pointer))
     {
         var obj = new UIImage(pointer);
         if (releasePointer)
         {
             CoreFoundation.CFFunctions.CFRelease(pointer);
         }
         return(obj);
     }
     else
     {
         return(null);
     }
 }
예제 #16
0
파일: NSArray.cs 프로젝트: artemy0/Quiz
 /// <summary>
 /// Creates a NSArray object from a pointer and release the pointer if required.
 /// </summary>
 /// <returns>The NSArray object.</returns>
 /// <param name="pointer">Pointer.</param>
 /// <param name="releasePointer">If set to <c>true</c> release pointer.</param>
 internal static NSArray <T> FromPointer(IntPtr pointer, bool releasePointer)
 {
     if (PInvokeUtil.IsNotNull(pointer))
     {
         var obj = new NSArray <T>(pointer);
         if (releasePointer)
         {
             CFFunctions.CFRelease(pointer);
         }
         return(obj);
     }
     else
     {
         return(null);
     }
 }
예제 #17
0
        private static void InternalSingleMatchCallback(IntPtr match, IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            GKTurnBasedMatch gkMatch = InteropObjectFactory <GKTurnBasedMatch> .FromPointer(match, ptr => new GKTurnBasedMatch(ptr));

            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKTurnBasedMatch#InternalSingleMatchCallback",
                PInvokeCallbackUtil.Type.Temporary,
                gkMatch, nsError, secondaryCallback);
        }
예제 #18
0
파일: NSURL.cs 프로젝트: artemy0/Quiz
 /// <summary>
 /// Creates a NSURL object from a pointer and release that pointer if required.
 /// </summary>
 /// <returns>The NSURL object.</returns>
 /// <param name="pointer">Pointer.</param>
 /// <param name="releasePointer">If set to <c>true</c> release pointer.</param>
 internal static NSURL FromPointer(IntPtr pointer, bool releasePointer)
 {
     if (PInvokeUtil.IsNotNull(pointer))
     {
         var newURL = new NSURL(pointer);
         if (releasePointer)
         {
             CFFunctions.CFRelease(pointer);
         }
         return(newURL);
     }
     else
     {
         return(null);
     }
 }
예제 #19
0
        private static void InternalRequestAccessForEntityTypeCallback(bool granted, /* NSError */ IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            // Invoke consumer callback.
            PInvokeCallbackUtil.PerformInternalCallback(
                "CNContactStore#InternalRequestAccessForEntityTypeCallback",
                PInvokeCallbackUtil.Type.Temporary,
                granted,
                nsError,
                secondaryCallback);
        }
예제 #20
0
        /// <summary>
        /// Returns the contact name, formatted with the specified formatter.
        /// </summary>
        /// <returns>The from contact.</returns>
        /// <param name="contact">Contact.</param>
        /// <param name="style">Style.</param>
        public static NSString StringFromContact(CNContact contact, CNContactFormatterStyle style)
        {
            if (contact == null)
            {
                return(null);
            }

            NSString str = null;
            var      ptr = C.CNContactFormatter_stringFromContact(contact.ToPointer(), style);

            if (PInvokeUtil.IsNotNull(ptr))
            {
                str = new NSString(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(str);
        }
예제 #21
0
        private static void WriteToSavedPhotosAlbumCallback(
            /* UIImage */ IntPtr imagePtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            var image = InteropObjectFactory <UIImage> .FromPointer(imagePtr, p => new UIImage(p));

            var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "UIKitFunctions#WriteToSavedPhotosAlbumCallback",
                PInvokeCallbackUtil.Type.Temporary,
                image, error, secondaryCallback);
        }
예제 #22
0
파일: CNContact.cs 프로젝트: artemy0/Quiz
        /// <summary>
        /// Returns a string containing the localized contact property name.
        /// </summary>
        /// <returns>The localized string.</returns>
        /// <param name="key">A string containing the contact property key.</param>
        public NSString LocalizedStringForKey(NSString key)
        {
            if (key == null)
            {
                return(null);
            }

            NSString localizedStr = null;
            var      ptr          = C.CNContact_localizedStringForKey(key.ToPointer());

            if (PInvokeUtil.IsNotNull(ptr))
            {
                localizedStr = new NSString(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(localizedStr);
        }
예제 #23
0
        private static void PlayersErrorCallback(
            /* InteropNSArray<GKPlayer> */ IntPtr playerArrayPtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            var array = InteropObjectFactory <NSArray <GKPlayer> > .FromPointer(playerArrayPtr, p => new NSArray <GKPlayer>(p));

            var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKMatchmaker#PlayersErrorCallback",
                PInvokeCallbackUtil.Type.Temporary,
                array, error, secondaryCallback);
        }
예제 #24
0
        private static void MatchErrorCallback(
            /* InteropGKMatch */ IntPtr matchPtr, /* InteropNSError */ IntPtr errorPtr, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            var match = InteropObjectFactory <GKMatch> .FromPointer(matchPtr, p => new GKMatch(p));

            var error = PInvokeUtil.IsNotNull(errorPtr) ? new NSError(errorPtr) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKMatchmaker#MatchErrorCallback",
                PInvokeCallbackUtil.Type.Temporary,
                match, error, secondaryCallback);
        }
예제 #25
0
파일: NSPredicate.cs 프로젝트: artemy0/Quiz
        /// <summary>
        /// Creates and returns a new predicate formed by creating a new string with a given format and parsing the result.
        /// </summary>
        /// <returns>The with format.</returns>
        /// <param name="predicateFormat">Predicate format.</param>
        public static NSPredicate PredicateWithFormat(NSString predicateFormat)
        {
            if (predicateFormat == null)
            {
                return(null);
            }

            NSPredicate predicate = null;
            var         ptr       = C.NSPredicate_predicateWithFormat(predicateFormat.ToPointer());

            if (PInvokeUtil.IsNotNull(ptr))
            {
                predicate = new NSPredicate(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(predicate);
        }
예제 #26
0
        /// <summary>
        /// Returns the localized name for the property associated with the specified key.
        /// </summary>
        /// <returns>The string for key.</returns>
        /// <param name="key">Key.</param>
        public static NSString LocalizedStringForKey(NSString key)
        {
            if (key == null)
            {
                return(null);
            }

            var      ptr          = C.CNPostalAddress_localizedStringForKey(key.ToPointer());
            NSString localizedStr = null;

            if (PInvokeUtil.IsNotNull(ptr))
            {
                localizedStr = new NSString(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(localizedStr);
        }
예제 #27
0
        /// <summary>
        /// Returns the delimiter to use between name components.
        /// </summary>
        /// <returns>The for contact.</returns>
        /// <param name="contact">Contact.</param>
        public static NSString DelimiterForContact(CNContact contact)
        {
            if (contact == null)
            {
                return(null);
            }

            NSString str = null;
            var      ptr = C.CNContactFormatter_delimiterForContact(contact.ToPointer());

            if (PInvokeUtil.IsNotNull(ptr))
            {
                str = new NSString(ptr);
                CFFunctions.CFRelease(ptr);
            }
            return(str);
        }
예제 #28
0
        /// <summary>
        /// Returns a new labeled value identifier object with the specified label and value.
        /// </summary>
        /// <returns>The value with label.</returns>
        /// <param name="label">Label.</param>
        /// <param name="value">Value.</param>
        public static CNLabeledValue <T> LabeledValueWithLabel(NSString label, T value)
        {
            if (value == null)
            {
                return(null);
            }

            var ptr = C.CNLabeledValue_labeledValueWithLabel(label == null ? IntPtr.Zero : label.ToPointer(), value.ToPointer());
            CNLabeledValue <T> instance = null;

            if (PInvokeUtil.IsNotNull(ptr))
            {
                instance = new CNLabeledValue <T>(ptr);
                CFFunctions.CFRelease(ptr);
            }

            return(instance);
        }
예제 #29
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);
        }
예제 #30
0
        private static void InternalLoadPhotoForSizeCallback(IntPtr photo, IntPtr error, IntPtr secondaryCallback)
        {
            if (PInvokeUtil.IsNull(secondaryCallback))
            {
                return;
            }

            // Create the UIImage from the pointer.
            UIImage uiImage = InteropObjectFactory <UIImage> .FromPointer(photo, ptr => new UIImage(ptr));

            // A new NSError object is always created on native side, so no need
            // to check the binder pool for reusing an existing one.
            NSError nsError = PInvokeUtil.IsNotNull(error) ? new NSError(error) : null;

            PInvokeCallbackUtil.PerformInternalCallback(
                "GKPlayer#InternalLoadPhotoForSizeCallback",
                PInvokeCallbackUtil.Type.Temporary,
                uiImage, nsError, secondaryCallback);
        }