Can phonegap app work in background?
what I mean is working in totally background, e.g. even the screen is shut down, the app is running and can send notifications with a sound.
My app is used for watching price changes. There will be an alert with a sound when a price changes.
So, the answer should be yes or no? Thanks.
Here is some links which can help you in this
link 1 : Similar SO question
link 2 : Red-Folder Blog
link 3 : BackgroundService Plugin in GitHub
Update
link 4 : Phonegap background service on iOS4
link 5 : phonegap background service in iOS5
Since there came another possible solution with iOS 7, I'm gonna provide an additional answer for users of iOS 7 and further.
The new Background Fetch feature, makes it possible to regularly update content for an app which is in the background. The time interval of the fetching cannot be set by the user, but is rather set by the iOS based on its user's statistics (app usage, etc.).
This new feature can be accessed with PhoneGap/Cordova via plugins - fortunately there has already been developed a plugin providing this access. You can install it to your Cordova project by
cordova plugin add https://github.com/christocracy/cordova-plugin-background-fetch.git
In conjunction with a plugin providing access to iOS's local notifications, this works wonders. Such a plugin has also been developed, for example this one. Install it to your Cordova project by
cordova plugin add https://github.com/katzer/cordova-plugin-local-notifications.git
These plugins can now be combined in your javascript code, to execute background activities:
function onDeviceReady() {
var Fetcher = window.plugins.backgroundFetch;
// Your background-fetch handler.
var fetchCallback = function() {
console.log('BackgroundFetch initiated');
// perform your ajax request to server here
$.get({
url: '/heartbeat.json',
callback: function(response) {
// process your response and whatnot.
window.plugin.notification.local.add({ message: 'Just fetched!' }); //local notification
Fetcher.finish(); // <-- N.B. You MUST called #finish so that native-side can signal completion of the background-thread to the os.
}
});
}
Fetcher.configure(fetchCallback);
}
This fetching plugin is using the UIApplicationBackgroundFetchIntervalMinimum
value for the fetching interval, this results in the fastest possible fetching periodicity.