Pause and resume listeners that are not working on the phone on iOS4.3 and iOS 5

I created my own application on iPhone4 with iOS 4.3

in my bodyload application i'm m

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

and in the same file I write a function

 Game.prototype.resumeListener= function() { console.log("in resumeListener"); this.PauseGame(false); } Game.prototype.pauseListener= function() { this.PauseGame(true); } 

this code works fine in Android and when I manually minimize the application, but when the application is interrupted by a voice incoming call, the application does not stop.

The main suspend and resume event does not fire.

I am using Phonegap1.4.1

+4
source share
3 answers

I believe that your event listeners are not set, because you use Object.bind() for handler functions, and .bind() not available in iOS WebKit widgets. (It depends on what .bind() Available in WebKit versions (Chrome and Safari) on the desktop.)

A simple solution is to add a polyfill definition for Object.bind (). I am using one of the MDN binding documentation page and have not had any problems with this.

+1
source

sorry, but I can not make a comment yet;)

Have you checked two other events (active and resigned only for ios)? Additional 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

0
source

You need to add your listeners to deviceready, not to onLoad. Just like here, for example

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

Hope this helps :)

0
source

Source: https://habr.com/ru/post/1412954/


All Articles