跳转到内容

本地存储

FRVR.localStorage 是一个异步、与渠道无关的封装,底层会按当前平台选择合适的存储后端(Web 上通常是 window.localStorage、Android 上是 SharedPreferences、iOS 上是 NSUserDefaults)。

直接用它,不要再用 window.localStorage —— 它在所有渠道行为一致,在不支持持久化的环境下会优雅降级到内存存储。

await FRVR.localStorage.setItem('coins', '100');
const coins = await FRVR.localStorage.getItem('coins');
await FRVR.localStorage.removeItem('coins');

值都是字符串。对象自己序列化:

await FRVR.localStorage.setItem('inventory', JSON.stringify(inventory));
const json = await FRVR.localStorage.getItem('inventory');
const inv  = json ? JSON.parse(json) : [];
用本地存储的场景……云端存储 的场景……
数据丢了重生成成本很低丢了就毁掉玩家的进度
是设备相关的(偏好、缓存)应该跟着玩家跨设备走
不需要登录玩家已登录

本地存储:get / set / remove

loading SDK…