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)); } }
/// <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); }
/// <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); }
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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); } }
/// <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); }
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); }
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); }
/// <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); }
/// <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); } }
/// <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); } }
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); }
/// <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); } }
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); }
/// <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); }
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); }
/// <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); }
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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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); }