跳转到内容
- 环境检测:始终使用
isInApp() 检测运行环境,确保代码兼容性
- 异步方法:
getEnv、getHostSettings 等返回 Promise,需要 await 或 .then()
- 取消监听:
onForeground、onBackground、subscribe 返回取消函数,在组件卸载时调用;onBackPressed 使用 offBackPressed() 取消
- TAB 页面:
closePage() 在 TAB 页面中无效果
- 内部接口:
onJSBridgeReady 由 SDK 自动调用,业务代码请勿主动调用
- 超时处理:异步方法超时后会 reject 并返回
TIMEOUT 错误,各方法超时时间如下:
- 5 秒:
getEnv、getAppName、getAppIcon、getHostSettings/ByKey、fileExists、createDir、reportEvent、pay.getProviders、hideBannerAd
- 10 秒:
requestShortUrl、requestShortUrlWithHtml、deleteFile、moveFile、listDir
- 30 秒:
getFileMd5、readFile、writeFile、getAttribution、pay.restorePurchases、showBannerAd
- 60 秒:
unzipFile、zipDir、requestLogin、showInterstitialAd
- 120 秒:
showRewardAd、showRewardedInterstitialAd
- 190 秒:
pay.purchase(Native IAP 路径,含用户在支付界面的操作时间;Web 收银台 inline 路径不设固定超时,按 pollInterval × maxPolls 轮询)
- 无超时:
callHostMethod、downloadFile(长时间任务,需业务层自行控制)