Varun Agarwal
Varun Agarwal

Reputation: 309

pause and resume listeners not working in phonegap on iOS4.3 and iOS 5

I was making a native app in iPhone4 with iOS 4.3

in my Body onLoad i m adding

document.addEventListener("pause", Game.prototype.pauseListener.bind(this), false);
document.addEventListener("resume", Game.prototype.resumeListener.bind(this), false); 

and in that same file i m writing a function

Game.prototype.resumeListener= function()
{

    console.log("in resumeListener");
    this.PauseGame(false);
}

Game.prototype.pauseListener= function()
{
        this.PauseGame(true);

}

this code is working perfectly fine in Android and when i manually minimise the app, but when the application is interrupted by a voice incoming call the application dont pause.

Basically Pause and Resume event are not fired.

I m using Phonegap1.4.1

Upvotes: 4

Views: 3823

Answers (3)

klm
klm

Reputation: 712

I believe your event listeners are not being established because you are using Object.bind() on the handler functions, and .bind() is not available in the iOS WebKit widget. (This is surpising because .bind() is available in the desktop WebKit (Chrome and Safari) versions.)

The easy solution is to add a polyfill definition for Object.bind(). I use the one from the MDN bind documentation page, and haven't had any problems with it.

Upvotes: 1

coderslay
coderslay

Reputation: 14370

You need to add your listeners in the deviceready instead of in the onLoad. Just like here for example

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    document.addEventListener("pause", onPause, false);
}

function onPause() {
}

Hope it helps :)

Upvotes: 0

Mario
Mario

Reputation: 758

sorry but i cant make a comment yet ;)

have you checked the two other events (active and resign only for ios)? more information: http://shazronatadobe.wordpress.com/2012/03/14/apache-cordova-lifecycle-events-in-ios-4-versus-ios-5/

or see iOS Quirks in the documentation: http://docs.phonegap.com/en/1.6.1/cordova_events_events.md.html#pause

Upvotes: 0

Related Questions