Exemplo n.º 1
0
        public void RemoveObjectForKey(string key)
        {
            IntPtr handle = ObjC.ToNSString(key);

            ObjC.MessageSendIntPtr(Handle, "removeObjectForKey:", handle);
            ObjC.MessageSend(handle, "release");
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public void SetObjectForKey(NSObject obj, string key)
        {
            IntPtr handle = ObjC.ToNSString(key);

            ObjC.MessageSendIntPtr(Handle, "setObject:forKey:", obj.Handle, handle);
            ObjC.MessageSend(handle, "release");
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public string StringFromNumber(double number)
        {
            IntPtr handle = ObjC.ToNSNumber(number);
            string text   = ObjC.MessageSendString(Handle, "stringFromNumber:", handle);

            ObjC.MessageSend(handle, "release");
            return(text);
        }
Exemplo n.º 7
0
 public object MarshalNativeToManaged(IntPtr pNativeData)
 {
     if (pNativeData == IntPtr.Zero)
     {
         return(default(string));
     }
     return(ObjC.FromNSUrl(pNativeData));
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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)));
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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)));
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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");
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        public static double FromNSNumber(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return(default(double));
            }

            return(ObjC.MessageSendDouble(handle, "doubleValue"));
        }
Exemplo n.º 16
0
        public static string FromNSString(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            return(Marshal.PtrToStringAuto(ObjC.MessageSendIntPtr(handle, "UTF8String")));
        }
Exemplo n.º 17
0
        public static string FromNSUrl(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            return(FromNSString(ObjC.MessageSendIntPtr(handle, "absoluteString")));
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        public IntPtr MarshalManagedToNative(object managedObj)
        {
            string text = managedObj as string;

            if (text == null)
            {
                return(IntPtr.Zero);
            }
            return(ObjC.ToNSUrl(text));
        }
Exemplo n.º 20
0
        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));
        }
Exemplo n.º 21
0
        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");
            }
        }
Exemplo n.º 22
0
        public static string[] FromNSSet(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                return(null);
            }

            IntPtr array = ObjC.MessageSendIntPtr(handle, "allObjects");

            return(FromNSArray(array));
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
        public virtual void Dispose()
        {
            GC.SuppressFinalize(this);

            if (Handle != IntPtr.Zero)
            {
                Runtime.UnregisterNSObject(Handle);
                Callbacks.UnsubscribeAll(this);
                if (_shouldRelease)
                {
                    ObjC.MessageSend(Handle, "release");
                }
            }
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
 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);
     }
 }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
        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));
        }