crh-jssdk 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -260,6 +260,8 @@ var Bridge = /** @class */ (function () {
260
260
  this.bridge = null;
261
261
  this.initPromise = null;
262
262
  this.isConnecting = false; // 标记是否正在连接,避免重复添加监听器
263
+ // 标记bridge.init是否已调用,避免在iOS环境下重复初始化导致"init called twice"错误
264
+ this._bridgeInitCalled = false;
263
265
  this.initPromise = this.init();
264
266
  }
265
267
  /**
@@ -270,16 +272,18 @@ var Bridge = /** @class */ (function () {
270
272
  return new Promise(function (resolve) {
271
273
  _this.connectWebViewJavascriptBridge(function (bridge) {
272
274
  _this.bridge = bridge;
273
- // 确保bridge.init存在且是函数
274
- if (bridge && typeof bridge.init === 'function') {
275
+ // 确保bridge.init存在且是函数,且未初始化过
276
+ // 在iOS环境下,App原生可能已经调用过bridge.init(),再次调用会报错"init called twice"
277
+ if (bridge && typeof bridge.init === 'function' && !_this._bridgeInitCalled) {
275
278
  bridge.init(function () {
276
279
  console.log('Bridge初始化完成');
277
280
  resolve();
278
281
  });
282
+ _this._bridgeInitCalled = true;
279
283
  }
280
284
  else {
281
- // 如果bridge已经初始化过,直接resolve
282
- console.log('Bridge已存在,跳过初始化');
285
+ // 如果bridge已经初始化过或init不存在,直接resolve
286
+ console.log('Bridge已存在或init已调用,跳过初始化');
283
287
  resolve();
284
288
  }
285
289
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crh-jssdk",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "crh-jssdk",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {