字节小程序
开发者社区
小程序小游戏
登录
报错getUserCloudStorage、getOpenDataContext

报错getUserCloudStorage、getOpenDataContext

5839浏览作者: lixiangyan1314

本例用微信小游戏做对比:

1.开放数据域问题 getOpenDataContext

复现步骤:

1.新建文件目录 src/myOpenDataContext/index.js,
    2.在game.json中配置 "openDataContext""src/myOpenDataContext"
    3. 在主域game.js中写入

  const openCtx = tt.getOpenDataContext();
    openCtx.postMessage({
        company: "bytedance 啦啦啦啦",
    });

在子域src/myOpenDataContext/index.js中写入

tt.onMessage(data => {
    console.log('接收开放数据域', data);
});

结果:

字节小游戏报错
字节小游戏报错
微信小游戏正确执行
1618554698(1).png

2.开放数据域 getUserCloudStorage

复现步骤:
  1. 在主域game.js写 setUserCloudStorage函数
let value2 = [
        {score: 10,nickname: '小燕子'},
        {score: 9,nickname: '翠浓'}
    ]
    tt.setUserCloudStorage({
        KVDataList: [
            {
                key: 'scoreList',
                value: JSON.stringify(value2)
            }
        ],
        success: (res) => {
            console.log("set云存储成功11", res);
        },
        fail: (err) => {
            console.log("set失败", err);
        },
        complete: (res) => {
            console.log("set完成", res);
        },
    })

2. 在子域写getUserCloudStorage函数来获取

tt.getUserCloudStorage({
    keyList: ["scoreList"],
    success: (res) => {
      let values = res.KVDataList[0].value
      console.log("get云存储成功", res);
      console.log('获取解析结果', JSON.parse(values))
    },
    fail: (res) => {
      console.log("get失败", res);
    },
    complete: (res) => {
      console.log("get完成", res);
    },
  })

结果

  1. 字节小游戏毫无反应;
  2. 微信小游戏可以正确获取结果
  3. 1618555093(1).png

总结:都用了相同的方法,结果是微信全都正确执行,字节报错一大堆,谁来解释一些

最后一次编辑于 2021年04月16日
加载中