抖音开放平台Logo
开发者文档
控制台
  • API 概览
  • C# API
  • 开放接口
  • 转发
  • 群聊
  • 关注
  • 数据分析
  • 基础
  • 渲染
  • 设备
  • 文件
  • 位置
  • 媒体
  • 网络
  • 转发
  • 数据缓存
  • 本地数据缓存
  • tt.clearStorage
  • tt.clearStorageSync
  • tt.getStorage
  • tt.getStorageSync
  • tt.getStorageInfo
  • tt.getStorageInfoSync
  • tt.removeStorage
  • tt.removeStorageSync
  • tt.setStorage
  • tt.setStorageSync
  • 广告
  • 界面
  • 支付
  • Worker
  • tt.getStorage
    收藏
    我的收藏

    基础库 1.0.0 开始支持本方法,这是一个异步方法。

    获取本地缓存数据。

    前提条件
    业务背景
    使用限制
    注意事项
    相关教程

    语法

    tt.getStorage(options)

    参数说明

    options 为 object 类型,属性如下:

    属性名类型默认值必填说明最低支持版本
    keystring

    键名

    1.0.0
    successfunction
    接口调用成功的回调函数
    1.0.0
    failfunction
    接口调用失败的回调函数
    1.0.0
    completefunction
    接口调用结束的回调函数(调用成功、失败都会执行)
    1.0.0

    回调成功

    object 类型,属性如下:

    属性名类型说明最低支持版本
    datastring | object | number | boolean | null | undefined | array

    本地缓存数据类型

    键名对应的数据,如无数据或数据类型不支持会返回空字符串

    1.0.0
    errMsgstring
    "getStorage:ok"
    1.0.0

    回调失败

    object 类型,属性如下:

    属性名类型说明最低支持版本
    errMsgstring
    "getStorage:fail" + 详细错误信息
    1.0.0

    错误码

    errNoerrMsg说明最低支持版本
    21101data not found, key == %s
    小游戏框架内部错误,有需要请创建工单咨询
    1.0.0
    20000internal error
    小游戏框架内部错误,有需要请创建工单咨询
    1.0.0
    20001invalid param
    参数错误
    1.0.0
    20000key is illegal
    1.0.0
    21000data not found, key == %@
    1.0.0
    -1promise not call
    小游戏框架内部错误,有需要请创建工单咨询
    1.0.0
    10102Methord %@ not implement
    小游戏框架内部错误,有需要请创建工单咨询
    1.0.0

    扫码体验

    请使用字节宿主APP扫码

    代码示例

    开发者工具中预览

    tt.getStorage({ key: "didShownAd", success(res) { console.log(res); }, fail(res) { console.log("getStorage调用失败"); }, });