I have worked on an app like a birthday reminder. Here i need a UI and background thread simultaneously: a thread that starts running after installing app and is always running in background, not affected by the UI. Opening or closing the UI should not affect the thread. It runs until the app is uninstalled. The thread always checks for updates in a database every 1 minute, silently in background .
The problem is when I close the UI, the thread is stopped automatically, and when i again open the app UI, it starts again.
Why is this? I want my thread always running..
Related
My iOS app gets terminated when put in background. I get the following logs in the device console:
Background Task 160 (""), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.
followed by
Background task still not ended after expiration handlers were called: . This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(_:) to avoid this.
and the app terminates and restarts on resuming from background
The new metric kit background exit data (iOS 14) is also reporting that BackgroundTaskAssertionTimeoutExits are killing my app
On breaking on UIApplicationEndBackgroundTaskError, I get the following backtrace:
I have not implemented any background tasks myself but there are some third party libraries integrated in the app that do.
What is the right way to debug this?
If you did not start any background task, and you do not perform anything most likely some of your 3rd party frameworks are causing the crash.
Update to latest version of all your dependencies, to see if the issue was fixed.
If your issue is easily reproducible, try to disable them 1 by 1 to see which is causing the crash.
After that go on the library support page and see if there are any bugs for your issue and if not open a bug.
Start with the usual suspects, Analytics, Loggers and go on.
Have a look also at this thread: App is crashing on only iOS 13 in the background mode
I have two drivers, one for my app and one for Chrome.
The flow is like so:
Start the app driver, set up the app (app starts background process).
Start the Chrome driver, do some stuff there and quit this driver.
But what I actually want to do is this:
Start the app driver, set up the app (app starts background process).
Close this app, but leave the background process running
Start the Chrome driver, do some stuff there and quit this driver.
Open back up the app which I have closed in step 2
Quitting the driver (driver.quit()) is obviously not an option, since this also kills the background process. Same as with (driver.close_app()).
I was thinking about doing this via UI, by simply clicking the "Recent Button" and swiping up on my app, but how would I then get back the app?
My question: Is it possible to close the app without killing the background process, if so - how?
After asking in the Appium Forum the solution is as follows:
Put the app into background for an indefinite amount of time:
driver.background_app(-1)
and activate it once you need it again:
driver.activate_app("app.id")
When I launch my app from Xcode with Background Fetch mode, it works. But it should stop when I call callback handler, or after 30 seconds.
But it does not! When I click Pause, I may see my main thread does not do anything.
Is it some xcode-specific issue, or do I misunderstand something about background fetch?
Apps running under the Xcode debugger are not subject to the same background execution time limitations as a released app.
For example, if you looped, logging UIApplication property backgroundTimeRemaining on a released app, your app would be terminated when this value reached zero. Under the debugger your app would continue indefinitely, reporting a zero value.
I am writing an app for personal use that needs continuous background execution. Apple tries to make this difficult, but I found that declaring that my app uses background location updates and then creating background task (with no content, just a blank task) allows my app to run indefinitely when I run the project from Xcode. I do not understand why this works. I noticed that after about three minutes, when presumably the task is supposed to be terminated, I get the following error:
Can't endBackgroundTask: no background task exists with identifier 174256fe0, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
After this message, the app continues to run in the background normally. So, it seems that this indefinite execution is a bit of an exploit, which I'm fine with because I just want to make the app work.
However, when I run the app from the phone (i.e. not pressing the run button in my Xcode project), the background execution seems to stop after 3 minutes. This is a problem, and I can't seem to figure out why execution continues in one case but not in the other. What is the difference between running an app normally and running it through Xcode? Is there a simpler or better way to get the indefinite background execution I'm looking for given that I'm not trying to get this app published to the app store?
Since you're not submitting to the store - why not try this:
Enable the app for background audio services. Then, just play a silent audio file in the background on a constant loop?
The difference is that you are running through Xcode. Normal background limits are removed when running through the debugger.
I'm trying to debug an issue with my iPhone app that seems to be getting terminated while running on the device (it never happens in the simulator). The app is for iOS 8 only.
Once app enters the background (via the user hitting the home button) I start Significant-Change Location service. When a location updates happens while the app is suspended the system should put the app in the background where I then send an update to my server with the location. That operation is wrapped in a proper beginBackgroundTaskWithExpirationHandler to allow me the time needed to make the network call.
It appears though my app is getting terminated by the system because sometimes when I resume the app from the suspended state it is no longer in the view last seen when minimizing but is back at the root controller as if starting from a fresh launch. It does not appear to be due to a crash as I do not see it in the crash log nor is New Relic reporting such. The app is suspended though, not terminated, probably because it is getting launched again into the background from a location update.
The question is, is there a way to know that my app was indeed terminated by the system, and if so, for what reason(memory, exceeding background execution time, etc.) and at what time. Is there a log kept somewhere containing this information?
I'm under the impression I can not use applicationWillTerminate because the docs say this is not called when an app is suspend.
You may check in Devices page. (Shortcut is Command + Shift + 2)