weex [Android] 0.28.0源码 调用 fireEvent(..., EventResult callback),无回调或仅有一次回调

x8goxv8g  于 5个月前  发布在  Weex
关注(0)|答案(1)|浏览(64)

问题是因为在 script_bridge_in_multi_process.cppstd::unique_ptr<IPCResult> OnReceivedResult(IPCArguments *arguments) 方法中,获取 callback_id 的方式 long callback_id = arguments->get<long>(0); 总返回 1或0,导致java层找不到对应的回调监听。
详情如下:

std::unique_ptr<IPCResult> OnReceivedResult(IPCArguments *arguments) {
  /**
   * START
   * 2021/06/16
   * 原代码 long callback_id = arguments->get<long>(0); 总返回 1或0
   * 导致java层找不到对应的回调监听
   */
  const char *callback_id_str = getArumentAsCStr(arguments, 0);
  long callback_id;
  sscanf(callback_id_str,"%ld",&callback_id);
  /**
   * END
   */
  std::unique_ptr<WeexJSResult> result;
  result.reset(new WeexJSResult);
  if (arguments->getCount() > 1 && arguments->getType(1) == IPCType::BYTEARRAY &&
      arguments->getByteArray(1)->length > 0) {
    result->length = arguments->getByteArray(1)->length;
    char *string = new char[result->length + 1];
    result->data.reset(string);
    memset(string, 0, result->length);
    memcpy(string, arguments->getByteArray(1)->content, result->length);
    string[result->length] = '\0';
  }
  WeexCoreManager::Instance()->script_thread()->message_loop()->PostTask(
      weex::base::MakeCopyable([callback_id, result = std::move(result)]() {
        WeexCoreManager::Instance()
            ->script_bridge()
            ->core_side()
            ->OnReceivedResult(
                callback_id,
                const_cast<std::unique_ptr<WeexJSResult> &>(result));
      }));
  return createInt32Result(static_cast<int32_t>(true));
}

相关问题