如何解决InAppBrowser事件处理程序无法触发:Ionic 5 + Angular 10 +电容器
我在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!`); // Doesn't get here
console.log(`URL: [${event.url}]`); // or here (obvIoUsly).
if (event.url && event.url.includes('path-i-am-interested-in')) {
// Do useful stuff...
}
});
});
console.log(`browser object after subscription:`);
console.log(browser);
}
当我将其部署到iPhone 11模拟器或通过XCode绑定到我的iPhone 11时,console.log
调用都不会在侦听器中触发。
我使用此代码构建了一个Ionic-Vue项目,并且工作正常。为什么这不适用于Angular?
以下是具有完整实现的精简存储库:
https://bitbucket.org/aaronw322/ionic-inappbrowser-subscription/src/master/
自述文件概述了我安装/构建它的步骤。
以下是打开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","loadstop":{"type":"loadstop","loaderror":{"type":"loaderror","exit":{"type":"exit","customscheme":{"type":"customscheme","numHandlers":0,"message":{"type":"message","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}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。