SURESH KUMAR
SURESH KUMAR

Reputation: 403

Phonegap- trigger a call to javascript from ios while app enterintobackground

I have a phonegap application and want to call javascript function while the app enter into background to perform a webservice call to update the app status.For that i am using writejavascript function.But it didn't call that function.I don't know whether it is possible or not. If possible just give me an idea to do this stuff.Thanks in advance.

NSString *tojs = [NSString stringWithFormat:@"downloadMgr.updateStatus('%d');",status];

[self writeJavascript:tojs];

Upvotes: 1

Views: 564

Answers (2)

Grebe.123
Grebe.123

Reputation: 107

The pause event is not a lot of use on IOS:-

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: 0

Arjun T Raj
Arjun T Raj

Reputation: 3207

Use Phonegaps event 'pause' and resume i think this may help you. Eg:

 document.addEventListener("pause", onPause, false);

  function onPause() {
  // Handle the pause event
  }

Link

Full Example

<!DOCTYPE html>
 <html>
 <head>
  <title>Cordova Pause Example</title>

<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script type="text/javascript" charset="utf-8">

// Call onDeviceReady when Cordova is loaded.



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

// Cordova is loaded and it is now safe to make calls Cordova methods
//
function onDeviceReady() {
    document.addEventListener("pause", onPause, false);
    document.addEventListener("resume", onResume, false);

}

  function onResume() {
    // Handle the resume event
  }
// Handle the pause event
//
function onPause() {
}

 </script> </head> <body onload="onLoad()"></body> </html>   

Upvotes: 3

Related Questions