Background activity

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.

Now i don’t know if xojo or maybe MBS or ioskit support such feature.

looks like no easy solution.
I’ll keep investigating from your link.


Explained here.
Maybe @Jeremie_L or @Christian_Schmitz can fill in the blanks here?

Well, we could add some classes for this to the plugins if there is interest.


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.

1 Like

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.

So maybe you need to be using the App.Deactivating and Screen.Deactivating things to stop sockets an timers ?

I am using the app.deactivating.
Maybe I’m missing something though. I need to spend a time finding out what is breaking.

Can you add something to Unhandled exception and push the stack to some logging system, we use airtable for this.

That’s the alarming point. I am handing unhandled exceptions, and it’s still bombing.
I’ll find it!

@Chris_Halford - you should be able to get a crash log for your app using Xcode. That’d tell you what the crash is actually about.

1 Like

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.

I’ll keep digging.