【问题标题】:callback function attached to window event not executed after opening the iOS Control Center打开 iOS 控制中心后未执行附加到窗口事件的回调函数
【发布时间】:2020-03-10 20:44:12
【问题描述】:

在我的 IOS 离子应用程序中,我正在监听一个由 cordova 插件生成的窗口事件。 这是我用于监听事件并执行操作的代码。

window.addEventListener('event', (event) => {
            ...
                console.log("event received");

            doSomething();
          });
doSomething(){console.log("perform an action");}

一切正常,在我打开 IOS 控制中心(从底部向上滑动)之前,我能够接收到事件。再次关闭控制中心后,我可以看到事件已记录(“收到事件”),但从未调用函数 doSomething()。 有人遇到过类似情况吗?

【问题讨论】:

    标签: ios cordova ionic3 cordova-plugins


    【解决方案1】:

    由于事件是在 angular 之外生成的,我需要调用 ngZone.run 以让 angular 知道发生了某些事情并触发更改。我是这样弄的

    constructor(private zone: NgZone) {}
    
    ngOnInit(){
            window.addEventListener('event', (event) => {
    
                  this.ngZone.run(() => {
                    do stuff;
                  });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      相关资源
      最近更新 更多