跳到主要内容

设置

SettingsNSUserDefaults 的包装器,NSUserDefaults 是一个仅在 iOS 上可用的持久化键值存储。

示例


参考

方法

clearWatch()

tsx
static clearWatch(watchId: number);

watchId 是调用 watchKeys() 时返回的数字,用于标识最初的订阅。


get()

tsx
static get(key: string): any;

获取 NSUserDefaults 中指定 key 的当前值。


set()

tsx
static set(settings: Record<string, any>);

NSUserDefaults 中设置一个或多个值。


watchKeys()

tsx
static watchKeys(keys: string | array<string>, callback: () => void): number;

订阅并在 NSUserDefaults 中任一由 keys 参数指定的键的值发生变化时收到通知。返回一个 watchId 数字,可用于调用 clearWatch() 取消订阅。

备注

watchKeys() 设计上会忽略内部的 set() 调用,仅在 React Native 代码之外的变更发生时触发回调。