Beispiel #1
0
 public UserDefaultManager()
 {
     if (settings.ValueForKey(NumberKey) != null)
     {
         Number = settings.ValueForKey(NumberKey).ToString();
     }
 }
 private bool DoContainsKey(string key)
 {
     if (IsRoaming)
     {
         return(_store.ValueForKey(new NSString(key)) != null);
     }
     else
     {
         // TODO: see if there is a more efficient way of checking the key exists
         return(_defaults.ValueForKey(new NSString(key)) != null);
     }
 }
        public object GetValue(Type valueType, string key)
        {
            object value = null;

            if (valueType == typeof(string))
            {
                value = UserDefaults.StringForKey(key);
            }
            else if (valueType == typeof(int))
            {
                value = UserDefaults.IntForKey(key);
            }
            else if (valueType == typeof(bool))
            {
                value = UserDefaults.BoolForKey(key);
            }
            else if (valueType == typeof(float))
            {
                value = UserDefaults.FloatForKey(key);
            }
            else if (valueType == typeof(double))
            {
                value = UserDefaults.DoubleForKey(key);
            }
            else if (valueType == typeof(long))
            {
                value = (long)((NSNumber)UserDefaults.ValueForKey(new NSString(key)));
            }
            else
            {
                Log.Error(INCORRECT_VALUE_TYPE_ERROR);
            }

            return(value);
        }
        private void GetDocumentSaved()
        {
            NSUserDefaults defaults      = NSUserDefaults.StandardUserDefaults;
            NSData         encodedObject = (NSData)defaults.ValueForKey(DocumentSavedKey);

            // Check if there are documents saved
            if (encodedObject == null)
            {
                return;
            }

            // Get documents saved and build the list
            NSMutableArray listDoc = (NSMutableArray)NSKeyedUnarchiver.UnarchiveObject(encodedObject);

            DocumentsList = new List <Document>();

            for (nuint i = 0; i < listDoc.Count; i++)
            {
                DocumentArchive docSaved = listDoc.GetItem <DocumentArchive>(i);

                // Build Document c# object form DocumentArchive NsObject
                Document doc = new Document();
                doc.Name = docSaved.Name;
                doc.ServerRelativeUrl = docSaved.ServerRelativeUrl;
                doc.BytesArray        = docSaved.BytesArray;

                DocumentsList.Add(doc);
            }


            // Load data and reload TableView
            tableView.Source = new DocumentTableDataSource(this.DocumentsList, this);
            tableView.ReloadData();
        }
Beispiel #5
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            vc = new UIViewController();
            vc.View.BackgroundColor   = UIColor.Blue;
            window.RootViewController = vc;

            UIColor lastColor = UIColor.Green;

            NSTimer.CreateRepeatingScheduledTimer(1, () => {
                var defs  = new NSUserDefaults("group.com.xamarin.todaysharing", NSUserDefaultsType.SuiteName);
                var value = defs.ValueForKey(new NSString("key"));
                if (value == null)
                {
                    if (lastColor == UIColor.Yellow)
                    {
                        lastColor = UIColor.Orange;
                    }
                    else
                    {
                        lastColor = UIColor.Yellow;
                    }
                    vc.View.BackgroundColor = lastColor;
                }
                else
                {
                    vc.View.BackgroundColor = UIColor.Green;
                }
            });

            window.MakeKeyAndVisible();

            return(true);
        }
Beispiel #6
0
        public override void ViewDidLoad()
        {
            // Defaults are stored in ~/Library/Preferences/*.osu.macOS.Agent.plist
            if (defaults.ValueForKey((NSString)"location") != null)
            {
                if (!SelectLocation(defaults.StringForKey("location")))
                {
                    return;
                }
            }

            if (LoadCheckbox(MapMoveCheckbox))
            {
                MapMoveCheckboxClick(null);
            }
            if (LoadCheckbox(SkinMoveCheckbox))
            {
                SkinMoveCheckboxClick(null);
            }
            if (LoadCheckbox(ReplayOpenCheckbox))
            {
                ReplayOpenCheckboxClick(null);
            }
            if (LoadCheckbox(NotificationCheckbox))
            {
                NotificationsCheckboxClick(null);
            }
        }
Beispiel #7
0
 public static bool BoolForKey(this NSUserDefaults defaults, bool defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return(defaults.BoolForKey(key));
 }
Beispiel #8
0
 public static float FloatForKey(this NSUserDefaults defaults, float defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return(defaults.FloatForKey(key));
 }
Beispiel #9
0
 public static double DoubleForKey(this NSUserDefaults defaults, double defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return(defaults.DoubleForKey(key));
 }
Beispiel #10
0
 public static int IntForKey(this NSUserDefaults defaults, int defaultValue, string key)
 {
     if (defaults.ValueForKey(new NSString(key)) == null)
     {
         return(defaultValue);
     }
     return((int)defaults.IntForKey(key));
 }
Beispiel #11
0
        public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        {
            var defs  = new NSUserDefaults("group.com.shareapp.ios", NSUserDefaultsType.SuiteName);
            var value = defs.ValueForKey(new NSString("FilePathList"));

            Datas.SharedItems = new List <string>();
            Datas.SharedItems = (List <string>)JsonConvert.DeserializeObject(value.ToString(), typeof(List <string>));
            return(true);
        }
Beispiel #12
0
        private NSArray getTrackableEvents(string key)
        {
            var eventArrayData = userDefaults.ValueForKey(new NSString(key)) as NSData;

            if (eventArrayData == null)
            {
                return(new NSArray());
            }

            return(NSKeyedUnarchiver.UnarchiveObject(eventArrayData) as NSArray);
        }
Beispiel #13
0
        static int LaunchAppAndWaitForExit(string path, string[] args, bool activate = true)
        {
            var pid    = LaunchApplicationForPath(path, args, activate);
            var retval = WaitForExit(pid);             // returning exit code not implemented in Mono.

            // This hack works only with apps that write their exit code into their defaults under "ExitCode" key and PID under "PID" key.
            var bundleIdentifier = NSBundle.FromPath(path)?.BundleIdentifier;

            if (bundleIdentifier != null)
            {
                var defaults = new NSUserDefaults(bundleIdentifier, NSUserDefaultsType.SuiteName);
                if ((defaults.ValueForKey((NSString)"PID") is NSNumber num) && num.Int32Value == pid)
                {
                    if (defaults.ValueForKey((NSString)"ExitCode") is NSNumber exitCode)
                    {
                        retval = exitCode.Int32Value;
                    }
                }
            }
            return(retval);
        }
Beispiel #14
0
        static bool ShowDeviceBezels(InspectableWindow window)
        {
            var simDefaults = new NSUserDefaults(
                "com.apple.iphonesimulator",
                NSUserDefaultsType.SuiteName);

            const string ShowChromeSetting = "ShowChrome";

            return(simDefaults.ValueForKey(new NSString(ShowChromeSetting)) == null
                ? true
                : simDefaults.BoolForKey(ShowChromeSetting));
        }
        protected override string doRead(string dataId)
        {
            NSUserDefaults prefs = NSUserDefaults.StandardUserDefaults;
            NSObject       value = prefs.ValueForKey(new NSString(dataId));

            if (null != value)
            {
                return(((NSString)value).ToString());
            }
            else
            {
                return(null);
            }
        }
        public override void TouchesEnded(NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            var defs = new NSUserDefaults("group.com.xamarin.todaysharing", NSUserDefaultsType.SuiteName);

            if (defs.ValueForKey(new NSString("key")) != null)
            {
                defs.RemoveObject("key");
                View.BackgroundColor = UIColor.DarkGray;
            }
            else
            {
                defs.SetValueForKey(new NSString("value"), new NSString("key"));
                View.BackgroundColor = UIColor.Green;
            }
            defs.Synchronize();
        }
 public bool ContainsKey(string key)
 {
     return(_storage.ValueForKey(new NSString(key)) != null);
 }
 public static bool isGeofenceServiceEnabled()
 {
     return((userDefaults.ValueForKey(new NSString("com.accengage.sample.geofence.key")) != null) ? userDefaults.BoolForKey("com.accengage.sample.geofence.key") : true);
 }