flutter webview ios15.1 以后突然无法使用 jsBridge通讯问题解决 12月九日下午准备下班突然出现线上报错,刚升级ios15后的手机无法访问webview内容, ps:我们的webview内容同样需要token传递才能访问,因此jsBridge无法通讯会导致没有token让我们的webview无法访问。 尝试了很多方法,ios的wifi问题,webview的升级,ios插件的更新,最终在一个博客上找到答案,那就是页面尚未初始化完成造成的通讯获取token异常导致的无法访问,原本是在onWebViewCreated阶段,使用jsBridge.loadJs及_jsBridge.registerHandler,在onPageFinished,提供用户信息给到h5.ios升级后可能有个同步变异步的问题,原本在onWebViewCreated阶段调用的loadJs,改成在onPageFinished调用,问题得到了解决。 以下为当时出现的两个异常信息,希望遇到同样的问题的同学可以迅速解决。flutter遇到这种问题真的很麻,俩小时解决不了第一个想法就是用flutter再开发一遍,或者干脆用ios的原生去写一份通讯。
Unhandled Exception: PlatformException(evaluateJavaScript_failed, Failed evaluating JavaScript, JavaScript string was: 'javascript:WebViewJavascriptBridge._handleMessageFromNative('{"callbackId":"flutter_cb_0","data":"{\\"xdi\\":\\"5B7E8B02-C0B6-480A-8C44-737C9691584E\\",\\"X-xk-token\\":\\"XKTOKEN_1639102338574b827f8ca-2bf4-4f51-a25a-2e7fff98b185\\"}","handlerName":"getUserInfo"}');'
Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo={WKJavaScriptExceptionLineNumber=1, WKJavaScriptExceptionMessage=ReferenceError: Can't find variable: WebViewJavascriptBridge, WKJavaScriptExceptionColumnNumber=35, WKJavaScriptExceptionSourceURL=http://192.168.26.20:5000/app-h5/index.html?t=20211210#/courses/list, NSLocalizedDescription=A JavaScript exception occurred}, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
Error acquiring assertion: <Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}>
[ProcessSuspension] 0x122ef8900 - ProcessAssertion: Failed to acquire RBS assertion 'ConnectionTerminationWatchdog' for process with PID=30287, error: Error Domain=RBSServiceErrorDomain Code=1 "target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit" UserInfo={NSLocalizedFailureReason=target is not running or doesn't have entitlement com.apple.runningboard.assertions.webkit}
|