Settings
Settings 充当 NSUserDefaults 的封装器,NSUserDefaults 是仅在 iOS 上可用的持久键值存储。
¥Settings serves as a wrapper for NSUserDefaults, a persistent key-value store available only on iOS.
示例
¥Example
参考
¥Reference
方法
¥Methods
clearWatch()
static clearWatch(watchId: number);
watchId 是最初配置订阅时 watchKeys() 返回的号码。
¥watchId is the number returned by watchKeys() when the subscription was originally configured.
get()
static get(key: string): any;
获取 NSUserDefaults 中给定 key 的当前值。
¥Get the current value for a given key in NSUserDefaults.
set()
static set(settings: Record<string, any>);
在 NSUserDefaults 中设置一个或多个值。
¥Set one or more values in NSUserDefaults.
watchKeys()
static watchKeys(keys: string | array<string>, callback: () => void): number;
订阅以在 keys 参数指定的任何键的值在 NSUserDefaults 中更改时收到通知。返回可与 clearWatch() 一起使用以取消订阅的 watchId 号码。
¥Subscribe to be notified when the value for any of the keys specified by the keys parameter has been changed in NSUserDefaults. Returns a watchId number that may be used with clearWatch() to unsubscribe.
watchKeys() 在设计上会忽略内部 set() 调用,并且仅在 React Native 代码外部执行的更改时触发回调。
¥watchKeys() by design ignores internal set() calls and fires callback only on changes preformed outside of React Native code.