Angular 10+Ionic 5+Capacitor项目InAppBrowser事件处理器不触发问题
Ionic Angular项目InAppBrowser事件回调不触发问题
以下是在Ionic CLI生成的blank Angular+Capacitor初始项目的home.page.ts文件中添加的代码:
openInAppBrowser() { const exampleUrl = 'https://ionicframework.com/docs/components'; const options: InAppBrowserOptions = { usewkwebview: 'yes' }; const browser = this.iab.create(exampleUrl, '_blank', options); const eventTypes: InAppBrowserEventType[] = ['loadstart', 'loadstop', 'beforeload', 'exit', 'loaderror']; eventTypes.forEach(eventType => { browser.on(eventType).subscribe(event => { console.log(`Event ${eventType} fired!`); // 代码执行不到此处 console.log(`URL: [${event.url}]`); // 自然也执行不到这行 if (event.url && event.url.includes('path-i-am-interested-in')) { // 执行对应业务逻辑 } }); }); console.log(`Browser object after subscription:`); console.log(browser); }
将该项目部署到iPhone 11模拟器,或通过XCode连接iPhone 11真机调试时,监听器内的所有console.log语句都未触发执行。
使用相同代码搭建的Ionic-Vue项目,可正常运行该功能。为什么这段代码在Angular项目中无法正常工作?
作者提供了包含完整实现的精简示例仓库,README文件中列明了完成安装、构建的全部操作步骤。
调试日志
以下是打开InAppBrowser加载示例站点、点击页面链接、再点击InAppBrowser窗口底部的Done按钮后,XCode控制台输出的日志(日志中未出现任何预期的回调输出):
To Native Cordova -> InAppBrowser open InAppBrowser694511092 ["options": [https://ionicframework.com/docs/components, _blank, usewkwebview=yes]] 2020-11-07 09:26:23.859892-0500 App[22260:325714] WF: _userSettingsForUser : (null) 2020-11-07 09:26:23.860064-0500 App[22260:325714] WF: _WebFilterIsActive returning: NO ⚡️ [log] - Browser object after subscription: ⚡️ [log] - {"_objectInstance":{"channels":{"beforeload":{"type":"beforeload","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loadstart":{"type":"loadstart","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loadstop":{"type":"loadstop","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"loaderror":{"type":"loaderror","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"exit":{"type":"exit","handlers":{},"state":0,"fireArgs":null,"numHandlers":1,"onHasSubscribersChange":null},"customscheme":{"type":"customscheme","handlers":{},"state":0,"fireArgs":null,"numHandlers":0,"onHasSubscribersChange":null},"message":{"type":"message","handlers":{},"state":0,"fireArgs":null,"numHandlers":0,"onHasSubscribersChange":null}}}} ⚡️ [log] - onscript loading complete ⚡️ WebView loaded 2020-11-07 09:26:24.078843-0500 App[22260:325714] No 2020-11-07 09:26:24.090239-0500 App[22260:325714] didStartProvisionalNavigation ⚡️ [log] - Angular is running in development mode. Call enableProdMode() to enable production mode. ⚡️ [log] - Ionic Native: deviceready event fired after 91 ms ⚡️ [warn] - Native: tried calling StatusBar.styleDefault, but the StatusBar plugin is not installed. ⚡️ [warn] - Install the StatusBar plugin: 'ionic cordova plugin add cordova-plugin-statusbar' ⚡️ [warn] - Native: tried calling SplashScreen.hide, but the SplashScreen plugin is not installed. ⚡️ [warn] - Install the SplashScreen plugin: 'ionic cordova plugin add cordova-plugin-splashscreen' 2020-11-07 09:26:24.427205-0500 App[22260:325714] Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7fa6c450df80>. ⚡️ To Native -> App addListener 86862752 2020-11-07 09:41:26.240739-0500 App[22260:325714] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}> 2020-11-07 09:41:26.240903-0500 App[22260:325714] [ProcessSuspension] 0x10cc0ff00 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 22267, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}
内容的提问来源于stack exchange,提问作者atrain
相关产品推荐
相关产品推荐

