Websync breaks when Iphone goes to sleep

184 Views Asked by At

I have created an iPhone application using phoneGap and i have implemented the Websync functionality using javascript, all functionality are working fine, but my problem is that When Iphone goes to sleep mode than the app is still open and when you wakeup the phone websync doesnt work anymore.

2

There are 2 best solutions below

0
On

Generally speaking iOS apps are not allowed to maintain a permanent connections in the background.

http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Keep in mind the following about inactive apps:

Inactive The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.

enter image description here

0
On

iOS (and other mobile devices) don't allow JavaScript to run in the background when the device is sleeping. Battery life would suffer tremendously if it did.

However, WebSync 4 should automatically re-connect to the server after waking up. If you are using WebSync 3, you have to set a flag (stayConnected) to get the same behaviour:

client.connect({ stayConnected: true }); // WebSync 3 only