1

I have a phonegap app and I want to execute Javascript code in a background task. When the application enters background I start executing a javascript function which takes data out of a web database and sends some values to a web service, the returning data may toggle a push-notification to the user.

I found either how to call javascript from Objective-C here on Stackoverflow and how to implement Long-Running Background Tasks in the iOS SDK Documentation pages, but I haven't found anything in combining both (what I think is e.g.: When I invoke javascript code via a webview, does this View even exist when the App is in background?) so I want to ask some more experienced iOS Developers if this is even possible.

2 Answers 2

1

I don't think its really possible. Javascript requires a UIwebview to run (in realtime) and must be visible to the user. When an app is put in background only a small amount of tasks are allowed to run- webview not one of them.

Your better off sending your data to a web server that runs a cron-job or similar to send out a push notification via apples push notification server - You can also bypass this and use a service like http://urbanairship.com/

Sign up to request clarification or add additional context in comments.

2 Comments

I'm on exactly this way now. You confirmed what I assumed. I dont use urban airship though, because I read it´s reduced to 1 Mio Notifications a month for the free plan. I use the PushNotification Plugin on Github, Link: github.com/phonegap/phonegap-plugins/tree/master/iOS/…. Thanks anyway.
I have also used this plugin.. Works well!
1

I experimented with this on iOS 5+ and it's possible. I created a small PhoneGap plugin that demonstrates how this works. Check it out, and see the README for most of the info.

https://github.com/jocull/phonegap-backgroundjs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.