public void RemoveObjectForKey(string key) { IntPtr handle = ObjC.ToNSString(key); ObjC.MessageSendIntPtr(Handle, "removeObjectForKey:", handle); ObjC.MessageSend(handle, "release"); }
public static UIUserNotificationSettings GetSettingsForTypes(UIUserNotificationType types) { //NOTE: right now we don't have support for categories, it required UIUserNotificationCategory, which is a somewhat advanced scenario I'd say IntPtr handle = ObjC.MessageSendIntPtr(_classHandle, "settingsForTypes:categories:", (uint)types, IntPtr.Zero); return(Runtime.GetNSObject <UIUserNotificationSettings>(handle)); }
public void SetObjectForKey(NSObject obj, string key) { IntPtr handle = ObjC.ToNSString(key); ObjC.MessageSendIntPtr(Handle, "setObject:forKey:", obj.Handle, handle); ObjC.MessageSend(handle, "release"); }
public NSObject AddObserver(string name, Action <NSNotification> action, NSObject fromObject = null) { var handler = new Observer(action); Callbacks.Subscribe(handler, SelectorName, n => action(Runtime.GetNSObject <NSNotification>(n))); ObjC.MessageSend(Handle, "addObserver:selector:name:object:", handler.Handle, ObjC.GetSelector(SelectorName), name, fromObject == null ? IntPtr.Zero : fromObject.Handle); return(handler); }
public static string LocalizedStringFromNumber(double number, NSNumberFormatterStyle style) { IntPtr handle = ObjC.ToNSNumber(number); string text = ObjC.MessageSendString(_classHandle, "localizedStringFromNumber:numberStyle:", handle, (int)style); ObjC.MessageSend(handle, "release"); return(text); }
public string StringFromNumber(double number) { IntPtr handle = ObjC.ToNSNumber(number); string text = ObjC.MessageSendString(Handle, "stringFromNumber:", handle); ObjC.MessageSend(handle, "release"); return(text); }
public object MarshalNativeToManaged(IntPtr pNativeData) { if (pNativeData == IntPtr.Zero) { return(default(string)); } return(ObjC.FromNSUrl(pNativeData)); }
public static NSDictionary FromObjectAndKey(NSObject obj, string key) { IntPtr handle = ObjC.ToNSString(key); var dictionary = Runtime.GetNSObject <NSDictionary>(ObjC.MessageSendIntPtr(_classHandle, "dictionaryWithObject:forKey:", obj.Handle, handle)); ObjC.MessageSend(handle, "release"); return(dictionary); }
public static NSData FromFile(string path) { #if !XAMARIN path = Path.Combine(UnityEngine.Application.streamingAssetsPath, path); #endif return(Runtime.GetNSObject <NSData>(ObjC.MessageSendIntPtr(_classHandle, "dataWithContentsOfFile:", path))); }
public static NSData FromUrl(string url, NSDataReadingOptions mask, out NSError error) { IntPtr errorHandle; var data = Runtime.GetNSObject <NSData>(ObjC.MessageSendIntPtr_NSUrl(_classHandle, "dataWithContentsOfURL:options:error:", url, (uint)mask, out errorHandle)); error = errorHandle == IntPtr.Zero ? null : Runtime.GetNSObject <NSError>(errorHandle); return(data); }
public static UIImage FromFile(string filename) { #if !XAMARIN filename = Path.Combine(UnityEngine.Application.streamingAssetsPath, filename); #endif return(Runtime.GetNSObject <UIImage>(ObjC.MessageSendIntPtr(_classHandle, "imageWithContentsOfFile:", filename))); }
public NSObject ObjectForKey(string key) { IntPtr handle = ObjC.ToNSString(key); var value = Runtime.GetNSObject <NSObject>(ObjC.MessageSendIntPtr(Handle, "objectForKey:", handle)); ObjC.MessageSend(handle, "release"); return(value); }
public UIActivityViewController(string text, UIImage image) { IntPtr textHandle = ObjC.ToNSString(text); IntPtr array = ObjC.ToNSArray(new[] { textHandle, image.Handle }); ObjC.MessageSendIntPtr(Handle, "initWithActivityItems:applicationActivities:", array, IntPtr.Zero); ObjC.MessageSend(textHandle, "release"); }
public static NSDictionary FromObjectsAndKeys(NSObject[] objs, string[] keys) { var objectsHandle = ObjC.ToNSArray(objs); var keysHandle = ObjC.ToNSArray(keys); var dictionary = Runtime.GetNSObject <NSDictionary>(ObjC.MessageSendIntPtr(_classHandle, "dictionaryWithObjects:forKeys:", objectsHandle, keysHandle)); ObjC.ReleaseNSArrayItems(keysHandle); return(dictionary); }
public static double FromNSNumber(IntPtr handle) { if (handle == IntPtr.Zero) { return(default(double)); } return(ObjC.MessageSendDouble(handle, "doubleValue")); }
public static string FromNSString(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } return(Marshal.PtrToStringAuto(ObjC.MessageSendIntPtr(handle, "UTF8String"))); }
public static string FromNSUrl(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } return(FromNSString(ObjC.MessageSendIntPtr(handle, "absoluteString"))); }
public NSObject[] ObjectsForKeys(string[] keys) { var keysHandle = ObjC.ToNSArray(keys); var arrayPtr = Runtime.GetNSObject <NSObject>(ObjC.MessageSendIntPtr(Handle, "objectsForKeys:notFoundMarker:", keysHandle, new NSObject().Handle)); var array = ObjC.FromNSArray <NSObject>(arrayPtr.Handle); ObjC.ReleaseNSArrayItems(keysHandle); return(array); }
public IntPtr MarshalManagedToNative(object managedObj) { string text = managedObj as string; if (text == null) { return(IntPtr.Zero); } return(ObjC.ToNSUrl(text)); }
public static T[] FromNSSet <T>(IntPtr handle) where T : NSObject { if (handle == IntPtr.Zero) { return(null); } IntPtr array = ObjC.MessageSendIntPtr(handle, "allObjects"); return(FromNSArray <T>(array)); }
public static void ReleaseNSArrayItems(IntPtr handle) { uint count = ObjC.MessageSendUInt(handle, "count"); IntPtr obj; for (uint num = 0; num < count; num += 1) { obj = ObjC.MessageSendIntPtr(handle, "objectAtIndex:", num); MessageSend(obj, "release"); } }
public static string[] FromNSSet(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } IntPtr array = ObjC.MessageSendIntPtr(handle, "allObjects"); return(FromNSArray(array)); }
public static NSData FromFile(string path, NSDataReadingOptions mask, out NSError error) { #if !XAMARIN path = Path.Combine(UnityEngine.Application.streamingAssetsPath, path); #endif IntPtr errorHandle; var data = Runtime.GetNSObject <NSData>(ObjC.MessageSendIntPtr(_classHandle, "dataWithContentsOfFile:options:error:", path, (uint)mask, out errorHandle)); error = errorHandle == IntPtr.Zero ? null : Runtime.GetNSObject <NSError>(errorHandle); return(data); }
public virtual void Dispose() { GC.SuppressFinalize(this); if (Handle != IntPtr.Zero) { Runtime.UnregisterNSObject(Handle); Callbacks.UnsubscribeAll(this); if (_shouldRelease) { ObjC.MessageSend(Handle, "release"); } } }
public static IntPtr ToNSArray(IntPtr[] items) { IntPtr intPtr = Marshal.AllocHGlobal((IntPtr)(items.Length * IntPtr.Size)); for (int i = 0; i < items.Length; i++) { Marshal.WriteIntPtr(intPtr, i * IntPtr.Size, items[i]); } IntPtr array = ObjC.MessageSendIntPtr(ObjC.GetClass("NSArray"), "arrayWithObjects:count:", intPtr, items.Length); Marshal.FreeHGlobal(intPtr); return(array); }
public void SaveToPhotosAlbum(Action <NSError> callback = null) { if (callback == null) { UIImageWriteToSavedPhotosAlbum(Handle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } else { var dispatcher = new UIImageDispatcher(callback); Callbacks.Subscribe(dispatcher, SelectorName, (IntPtr obj, IntPtr e, IntPtr ctx) => { callback(e == IntPtr.Zero ? null : Runtime.GetNSObject <NSError>(e)); dispatcher.Dispose(); }); UIImageWriteToSavedPhotosAlbum(Handle, dispatcher.Handle, ObjC.GetSelector(SelectorName), IntPtr.Zero); } }
public static IntPtr ToNSSet(string[] items) { IntPtr[] strings = new IntPtr[items.Length]; for (int i = 0; i < items.Length; i++) { strings[i] = ToNSString(items[i]); } IntPtr array = ToNSArray(strings); IntPtr set = ObjC.MessageSendIntPtr(GetClass("NSSet"), "setWithArray:", array); //Release everything for (int i = 0; i < strings.Length; i++) { ObjC.MessageSend(strings[i], "release"); } return(set); }
public static T[] FromNSArray <T>(IntPtr handle) where T : NSObject { if (handle == IntPtr.Zero) { return(null); } uint count = ObjC.MessageSendUInt(handle, "count"); T[] array = new T[count]; IntPtr obj; for (uint num = 0; num < count; num += 1) { obj = ObjC.MessageSendIntPtr(handle, "objectAtIndex:", num); array[(int)num] = Runtime.GetNSObject <T>(obj); } return(array); }
public static string[] FromNSArray(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } uint count = ObjC.MessageSendUInt(handle, "count"); string[] array = new string[count]; IntPtr obj; for (uint num = 0; num < count; num += 1) { obj = ObjC.MessageSendIntPtr(handle, "objectAtIndex:", num); array[(int)num] = FromNSString(obj); } return(array); }
public static DateTime FromNSDate(IntPtr handle) { if (handle == IntPtr.Zero) { return(default(DateTime)); } double secondsSinceReferenceDate = ObjC.MessageSendDouble(handle, "timeIntervalSinceReferenceDate"); if (secondsSinceReferenceDate < -63113904000) { return(DateTime.MinValue); } if (secondsSinceReferenceDate > 252423993599) { return(DateTime.MaxValue); } return(new DateTime((long)(secondsSinceReferenceDate * 10000000 + 6.3113904E+17), DateTimeKind.Utc)); }