Spark Events issue with sleep/wake mobile app

Hi,

I’m creating a phonegap app for both (iOS/Android). I have subscribed to a specific event using (.onEvent), the problem is, when the iOS sleeps, wakes up again, it forgets the event and unsubscribes by itself.

A workaround would be to re-subscribe every time the device wakes, however, Android is different, sometimes it unsubscribes and sometimes it does not, so if I resubscribe it might have duplicate event listeners.

Is there a way I can clear all event listeners on a specific device object and re-add them all over again? Or if there is a better way to do it?

A similar scenario happens when the Connection (wifi or otherwise) is lost and reconnected.

If you are using NSURLSession and its task is a data task, the only way to go is the workaround as you did describe it.
From Apple’s docs

Because data tasks do not store the data to a file, they are not supported in background sessions.

I’m using Phonegap/Cordova (ie. the Javascript SDK).