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.
Not the same thing as what the OP was posting about, but you can get location info in the background (with the users permission, of course). One of my apps uses background location to continue collecting GPS tracks when the screen is off or when the users switches to another app. In Xojo, one needs to set: MobileLocation.AuthorizationStates.AuthorizedAlways and make sure that background modes Location is checked. The background modes capabilities lists other cases but I don’t know if Xojo is wired for those. Maybe with a declare?
OK thanks - I dit test your advise. In fact that did work, so that there was some background activity in the App. Unfortunately this did not happen in times the iPhone was not moved around. For my Project i need a reliable possibility to do some small activity like actualizing the app bade and keeping pending notifications actual. With this workaround this is not sure if the iPhone is not moving. And running a Localization service in background is consuming battery.
I spent time trying to work with declares - but it seems to me that I am not familiar enough with this
Maybe worth a feature request:
Could Xojo implement a BGAppRefreshTask as described inBGAppRefreshTask | Apple Developer Documentation a launch an App.BGAppRefreshTask event ? So dummies like me don’t have to cope with underlying declares?
Otherwise I woud appreciate any help for enabling a reliable background activity.