private static void _OnStoreChanged(object sender, NSNotificationEventArgs e) { if (_valuesChangedHandlers != null) { var reason = (NSUbiquitousKeyValueStoreChangeReasonValues)Enum.ToObject( typeof(NSUbiquitousKeyValueStoreChangeReasonValues), Convert.ToInt32(e.userInfo[NSUbiquitousKeyValueStore.ChangeReasonKey])); object[] keys = e.userInfo[NSUbiquitousKeyValueStore.ChangedKeysKey] as object[]; iCloudPrefsChange[] changes = new iCloudPrefsChange[keys.Length]; for (int i = 0; i < keys.Length; i++) { string key = keys[i] as string; // get old value object oldValue = _userDefaults.Object(USER_DEFAULTS_PREFIX + key); if ((oldValue is int) || (oldValue is long)) { oldValue = Convert.ToInt32(oldValue); } else if ((oldValue is double) || (oldValue is float)) { oldValue = (float)Convert.ToDouble(oldValue); } // clean new value, and set it in cache object newValue = store.Object(key); if (newValue == null) { _userDefaults.RemoveObject(USER_DEFAULTS_PREFIX + key); } else if (newValue is string) { _userDefaults.SetObject(newValue, USER_DEFAULTS_PREFIX + key); } else if ((newValue is int) || (newValue is long)) { // in case of long, convert it to int first newValue = Convert.ToInt32(newValue); _userDefaults.SetInteger((int)newValue, USER_DEFAULTS_PREFIX + key); } else if ((newValue is double) || (newValue is float)) { // in case of double, convert it to float first newValue = (float)Convert.ToDouble(newValue); _userDefaults.SetDouble((float)newValue, USER_DEFAULTS_PREFIX + key); } changes[i] = new iCloudPrefsChange(key, newValue, oldValue); } _valuesChangedHandlers(null, new iCloudPrefsChangedEventArgs(reason, changes)); } }
private static void _OnStoreChanged(object sender, NSNotificationEventArgs e) { if (_valuesChangedHandlers != null) { var reason = (NSUbiquitousKeyValueStoreChangeReasonValues)Enum.ToObject( typeof(NSUbiquitousKeyValueStoreChangeReasonValues), Convert.ToInt32(e.userInfo[NSUbiquitousKeyValueStore.ChangeReasonKey])); object[] keys = e.userInfo[NSUbiquitousKeyValueStore.ChangedKeysKey] as object[]; iCloudPrefsChange[] changes = new iCloudPrefsChange[keys.Length]; for (int i=0; i<keys.Length; i++) { string key = keys[i] as string; // get old value object oldValue = _userDefaults.Object(USER_DEFAULTS_PREFIX + key); if ((oldValue is int) || (oldValue is long)) { oldValue = Convert.ToInt32(oldValue); } else if ((oldValue is double) || (oldValue is float)) { oldValue = (float)Convert.ToDouble(oldValue); } // clean new value, and set it in cache object newValue = store.Object(key); if (newValue == null) { _userDefaults.RemoveObject(USER_DEFAULTS_PREFIX + key); } else if (newValue is string) { _userDefaults.SetObject(newValue, USER_DEFAULTS_PREFIX + key); } else if ((newValue is int) || (newValue is long)) { // in case of long, convert it to int first newValue = Convert.ToInt32(newValue); _userDefaults.SetInteger((int)newValue, USER_DEFAULTS_PREFIX + key); } else if ((newValue is double) || (newValue is float)) { // in case of double, convert it to float first newValue = (float)Convert.ToDouble(newValue); _userDefaults.SetDouble((float)newValue, USER_DEFAULTS_PREFIX + key); } changes[i] = new iCloudPrefsChange(key, newValue, oldValue); } _valuesChangedHandlers(null, new iCloudPrefsChangedEventArgs(reason, changes)); } }
/// <summary> /// Initializes a new instance of the <see cref="U3DXT.iOS.Data.iCloudPrefsChangedEventArgs"/> class. /// </summary> /// <param name="reason">Reason.</param> /// <param name="changes">Changes.</param> public iCloudPrefsChangedEventArgs(NSUbiquitousKeyValueStoreChangeReasonValues reason, iCloudPrefsChange[] changes) { this.reason = reason; this.changes = changes; }