版本:Next
设置
Settings 作为 NSUserDefaults 的包装器使用,它是一个仅在 iOS 上可用的持久化键值存储。
示例
参考
方法
clearWatch()
React TSX
static clearWatch(watchId: number);
watchId 是在最初配置订阅时由 watchKeys() 返回的数字。
get()
React TSX
static get(key: string): any;
获取 NSUserDefaults 中某个给定 key 的当前值。
set()
React TSX
static set(settings: Record<string, any>);
在 NSUserDefaults 中设置一个或多个值。
watchKeys()
React TSX
static watchKeys(keys: string | array<string>, callback: () => void): number;
订阅以在 NSUserDefaults 中指定的 keys 参数所包含的任意键的值发生变化时收到通知。返回一个可与 clearWatch() 一起使用以取消订阅的 watchId 数字。
备注
watchKeys() 按设计会忽略内部的 set() 调用,并且仅在 React Native 代码之外发生更改时触发回调。