Background Fetch doesn't work on iOS

104 views
Skip to first unread message

nickk...@gmail.com

unread,
Aug 22, 2016, 7:33:45 PM8/22/16
to CodenameOne Discussions
Using the sample here: https://www.codenameone.com/javadoc/com/codename1/background/BackgroundFetch.html and ensuring that I've added ios.background_modes=fetch to the build hints I get the following error in the console everytime the app goes into the background and nothing is ever output from the background task. Works on Android.


Requesting process (process details in here) is suspended and cannot obtain assertions

Display isBackgroundFetchSupported() returns true. Application Exits is NOT ticked.


Steve Hannah

unread,
Aug 22, 2016, 7:56:52 PM8/22/16
to codenameone...@googlegroups.com
Is that message printed immediately upon entering the background?  And is it every time it enters the background?
Do you have anything fancy going on inside your stop() method?  e.g. does stop() wait for anything to complete, or does it start any longer running work?
Does it ever start to run your background fetch handler at all?
Do you have any other background stuff going on at all in your app?  (e.g. background locations, background audio, native interfaces with background stuff, etc...)
Make sure you are calling the onComplete callback inside your background handler - and that it isn't running too long.  (I suggest just putting in a simple System.out.println() and the callback for testing until you get it working).

And always remember, for iOS, that you have virtually no control over when or if iOS will call your background handler.  

Steve

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/6e0577ec-4df9-4258-8957-863e746db6eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Steve Hannah
Software Developer
Codename One

nickk...@gmail.com

unread,
Aug 22, 2016, 8:11:20 PM8/22/16
to CodenameOne Discussions
Its immediately on entering the background, but after that it won't show the error again unless I force quit the app and run it again, i.e., switching between foreground and background won't trigger the error again.

stop is making a network call to our analytics system.

It never runs the background fetch handler at all.

No location or background audio, the only native interface is to the analytics SDK and its stopped in the stop method.

I'll try removing the analytics and any network calls in Background Fetch and go from there.

Cheers,
Nick

nickk...@gmail.com

unread,
Sep 13, 2016, 10:07:11 PM9/13/16
to CodenameOne Discussions, nickk...@gmail.com
Ok might be finally making progress on this.

The documentation says that the deadline is the time limit by which time the background fetch must be completed, it also mentions that its a 30 second limit, however in the implementation its hardcoded to send System.getTimeMillis() + 25 * 60 * 1000. Therefore relying on that deadline to manage what work can be done within the limit is wrong and will always fail and get killed by iOS.

Also I couldn't find an explanation or example of the boolean sent to onSuccess, turns out that it is true if you updated data (i.e., made a network call that updated something) and false if not. Calling true all the time when nothing was actually updated gets the task killed by iOS.

I'd suggest that the iOS implementation is updated to send 30 seconds back instead of 60.025 seconds and that the documentation is updated to explain the difference between true and false in the success callback. I think its more reliable now, will continue testing.
Reply all
Reply to author
Forward
0 new messages