For the complete documentation index, see llms.txt. This page is also available as Markdown.

Storage.getItems

功能说明

从移动应用的本地存储中一次性获取多个字符串值。即使应用退出后重新启动,数据也会保留。未保存的键也会包含在结果中,其值为 null

Toss应用 Android/iOS 5.270.0 可在及以上版本使用。调用前 Storage.getItems.isSupported()可通过其确认是否支持。若在不支持的版本中调用 UNSUPPORTED_APP_VERSION 会发生错误。

类型

Storage.getItems(keys: string[]): Promise<Record<string, string | null>>;

参数

type Keys = string[];

要获取的存储键列表。

响应

type GetItemsResult = Record<string, string | null>;

将请求的每个键及其存储的值作为对象返回。未保存的键的值为 null

错误

代码
说明

UNSUPPORTED_APP_VERSION

如果正在运行的 Toss 应用版本不支持此功能,则会在调用时立即发生。 Storage.getItems.isSupported()请事先通过其确认,发生时 error.message请将其展示给用户。

示例代码

import { Storage } from "@apps-in-toss/web-framework";

if (Storage.getItems.isSupported()) {
  const items = await Storage.getItems(["theme", "language"]);
  console.log(items.theme);
  console.log(items.language);
}

这有帮助吗?