I’m having trouble managing my app when it slips into the background or the phone goes to sleep.
I have some lengthy network activity that fails (socket errors and such).
I’d like to either allow the app to continue working in the background, or to be able to force it to just stop doing everything so I could resume when in the foreground again, and in some cases I’d like to keep it awake.
I don’t know what is possible.
I do see the “Background Modes” option modes under capabilities, but I’m confused about how to use those right.
it’s hard but you can get “some 30 seconds” of processing from a push notification in background mode. it did work in my tests but that’s a bout a year ago.
It basicly works like you send a push notification which has a background mode (fetch?) setting in it. This triggers your app (App.Opening) that runs for max 30 seco or so i believe.
You may want something different perhaps like keep the app running and just poll every x seconds on the sockets. You need background tasks to keep this up.
I believe that the event you are looking for is LaunchOptions. IIRC that event will fire if your running app is given a soft launch (not brought to the foreground) and you’ve got 30 seconds or so to do some processing. The amount of time seems to be dependent on the system load and if the device is in low power mode, your app may not run at all.
Also, remember that the user can change whether your app can run in the background at all, so don’t rely on it as the sole solution.
I am not sure that we are all talking about the same thing.
Perhaps that’s because what I looking for just isn’t possible in iOS.
This has been really hard to figure out. On the hardware my app has a tendency to crash when being activated after it went to the background. I cannot replicate this on the simulator.
It seems some things are working as expected in the background and some are not, resulting in Nil object exceptions.
So hard to debug when it only occurs on the hardware and not in simulator - and I am yet to be able to get this project to debug on my device.
I can see it looks like there is a nil object occurring, but I can’t make out what it is.
I populated the unhandled exception event in the app, and that’s not catching it.