public void Indexer()
        {
            using (var store = new NSUbiquitousKeyValueStore()) {
                using (var key = new NSString("key")) {
                    using (var value = new NSString("value")) {
                        store [key] = value;
#if __TVOS__
                        // broken on appletv devices running tvOS 14, test will fail when fixed
                        if ((Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckXcodeVersion(12, 0))
                        {
                            Assert.Null(store [key], "key 1");
                        }
                        else
#endif
                        Assert.AreEqual(value, store [key], "key 1");

                        store [(string)key] = value;
#if __TVOS__
                        // broken on appletv devices running tvOS 14, test will fail when fixed
                        if ((Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckXcodeVersion(12, 0))
                        {
                            Assert.Null(store [(string)key], "key 2");
                        }
                        else
#endif
                        Assert.AreEqual(value, store [(string)key], "key 2");
                    }
                }
            }
        }
        public void Indexer()
        {
            using (var store = new NSUbiquitousKeyValueStore()) {
                using (var key = new NSString("key")) {
                    using (var value = new NSString("value")) {
                        store [key] = value;
                        Assert.AreEqual(value, store [key], "key 1");

                        store [(string)key] = value;
                        Assert.AreEqual(value, store [(string)key], "key 2");
                    }
                }
            }
        }
    private void Run()
    {
        // For this example to work, you'll need to run this from two clients
        // Both will make somewhat random changes to the key-value store, which
        // will trigger the notification
        // Notifications only trigger when the key-value store is changed externally

        Debug.Log("Example 8 - Key Value Store");
        Debug.Log("Open this example on another client to start receiving KVS changed Notifications");

        store = NSUbiquitousKeyValueStore.DefaultStore;
        store.AddDidChangeExternallyNotificationObserver(OnKeyStoreChanged);
        StartCoroutine(SetRandomValues(30f));
    }
示例#4
0
        static iCloudPrefs()
        {
            if (CoreXT.IsDevice)
            {
                // get id from user defaults
                _userDefaults = NSUserDefaults.StandardUserDefaults();
                iCloudID      = _userDefaults.Object(ID_KEY) as string;

                store = NSUbiquitousKeyValueStore.DefaultStore();
                store.DidChangeExternally += _OnStoreChanged;

                NSFileManager.DefaultManager().UbiquityIdentityDidChange += _Init;
                CoreXT.ApplicationResumed += _Init;

                _Init();
            }
        }
        private void Initialize(string name)
        {
            switch (_locality)
            {
            case ApplicationDataLocality.Roaming:
                _store = NSUbiquitousKeyValueStore.DefaultStore;
                break;

            case ApplicationDataLocality.SharedLocal:
                _defaults = new NSUserDefaults(name, NSUserDefaultsType.SuiteName);
                if (_defaults == null)
                {
                    throw new ArgumentException("name");
                }
                break;

            default:
                _defaults = NSUserDefaults.StandardUserDefaults;
                break;
            }
        }