我想在暂停事件被触发时执行异步函数。
document.addEventListener("pause", function(){
console.log("puase fire"); //it get print in console
setTimeout(function(){
console.log("after 1 second"); //it not get print in console.
}, 1000);
}, false);
超时函数在恢复时执行,但如果终止或关闭应用程序,则完整的代码执行挂起。
最佳答案
它记录在 iOS Quirks 上
In the pause handler, any calls to the Cordova API or to native plugins that go through Objective-C do not work, along with any interactive calls, such as alerts or console.log(). They are only processed when the app resumes, on the next run loop.
所以,如果你想调用一些本地方法,它不会工作,console.log 也不会。
关于javascript - 暂停事件后,iOS 不执行异步或完整的 Javascript 代码(Cordova 应用程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48322816/