Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39988

pause event is not working properly in PhoneGap iPhone?

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?

Upvotes: 4

Views: 6448

Answers (2)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39988

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

Upvotes: 5

Devgeeks
Devgeeks

Reputation: 5647

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 ?

Upvotes: 2

Related Questions