跳到主要内容

设置

Settings 作为 NSUserDefaults 的包装器,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;

NSUserDefaultskeys 参数指定的任何键的值发生更改时,订阅通知。返回一个 watchId 数字,可与 clearWatch() 一起用于取消订阅。

注意: watchKeys() 默认忽略内部 set() 调用,仅在 React Native 代码外部执行的更改时触发回调。