在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"); } 

当我按主页button没有在控制台中的日志,但是当我点击应用程序(使它在前台),然后我的日志是

 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 

我不知道为什么在前台调用暂停函数。
有什么我做错了吗?

这是来自文档

iOS的怪癖

在暂停处理程序中,任何通过Objective-C的调用都将无法工作,也不会有任何交互式调用,如警报。 这意味着您不能调用console.log(及其变体),或者来自Plugins或PhoneGap API的任何调用。 这些只会在应用程序恢复时处理(在下一个运行循环中处理)。

我怀疑实际上发生的事情是,暂停事件中的console.log()并没有在简历上被触发,因为只是系统无法输出你的console.log(),直到它返回。

PhoneGapDelegate.m用于触发暂停事件( applicationWillEnterForeground:(UIApplication *)application )的Objective-C方法将其发送到JavaScript,但是到那时应用程序在后台被挂起。 在重新进入前台之前,JavaScript不能接收事件。

要testing这个,只需将您的应用程序背景更长一段时间…它应该导致他们的错误:

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

这似乎是PhoneGap中的一个错误。 也许你可以提出一个问题: https : //github.com/callback/callback-ios ?