pause event is not working properly in PhoneGap iPhone?

让人想犯罪 __ 提交于 2019-12-10 17:10:44

问题


This is my code

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

When i press the home button there is no log in the console however when I click the app (make it in foreground) then my log is

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

I don't know why pause function is called when it comes in foreground.
Is there anything that I'm doing wrong?


回答1:


This is from the docs

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).




回答2:


I suspect what is actually happening is that the console.log() from the pause event is not so much being fired on resume, as it's just that the system cannot output your console.log() until it comes back.

The Objective-C method in PhoneGapDelegate.m that fires the pause event (applicationWillEnterForeground:(UIApplication *)application) sends it to the JavaScript but by then the app is in the background and suspended. The JavaScript cannot receive the event until it re-enters the foreground.

To test this, simply background your app for a longer period of time... it should then cause their error:

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

This appears to be a bug in PhoneGap. Perhaps you could raise an issue at: https://github.com/callback/callback-ios ?



来源:https://stackoverflow.com/questions/8223020/pause-event-is-not-working-properly-in-phonegap-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!