暂停事件在PhoneGap iPhone中不能正常工作



这是我的代码

    //This is an event that fires when a PhoneGap application is put into the background.
    document.addEventListener("pause", onPause, false);
    //This is an event that fires when a PhoneGap application is retrieved from the background.
    document.addEventListener("resume", onResume, false);
    // Handle the pause event
    function onPause(){
    console.log("pause : app is put into background");
    }

    // Handle the resume event
    function onResume() {
    console.log("resume : app is put into foreground");
    }

当我按下home键时,控制台没有日志,但是当我点击应用程序(使其在前台)时,我的日志是

2011-11-22 12:11:37.206 Event[644:207] [INFO] pause : app is put into background
2011-11-22 12:11:37.206 Event[644:207] [INFO] resume : app is put into foreground

我不知道为什么当它出现在前台时要调用pause函数。
我做错什么了吗?

来自文档

iOS怪癖

在pause处理程序中,任何经过Objective-C的调用都不能工作,任何交互的调用也不能工作,比如警报。这意味着您不能调用console.log(及其变体),也不能从插件或PhoneGap API调用任何调用。这些只会在应用程序恢复时被处理(在下一个运行循环中处理)。

我怀疑实际发生的情况是,pause事件中的console.log()并没有在恢复时被触发,因为系统只是在它返回之前无法输出console.log()。

PhoneGapDelegate.m中触发暂停事件(applicationWillEnterForeground:(UIApplication *)application)的Objective-C方法将其发送给JavaScript,但此时应用程序处于后台并暂停。JavaScript无法接收事件,直到它重新进入前台。

要测试这一点,只需将应用置于较长时间的后台…然后它应该导致他们的错误:

void SendDelegateMessage(NSInvocation*): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode

这似乎是PhoneGap的一个bug。也许您可以在以下网址提出问题:https://github.com/callback/callback-ios ?

最新更新