ios – 暂停事件在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");
    }

当我按下主页按钮时,控制台中没有日志,但是当我单击应用程序(将其置于前台)时,我的日志就是

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 Quirks

In the pause handler,any calls that go through Objective-C will not work,nor will any calls that are interactive,like alerts. This means that you cannot call console.log (and its variants),or any calls from Plugins or the PhoneGap API. These will only be processed when the app resumes (processed on the next run-loop).

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...