Running App in Background/Terminated State - ios

I understand that this issue has already been covered extensively in the past, but I'd like to readdress it it appears that there is a lot of mixed messaging around the subject.
I have an application that should be periodically updated, roughly once a day at the minimum, to run some maintenance tasks. I have researched extensively on how to achieve this behaviour, but options such as background fetch and silent push notifications do not appear to work when the app has been terminated (swiped up on) by the user. (see this link for app states)
Will IOS wake up my app if it is in the terminated state, for example, if a user has swiped up on the app? I would like to find a solution that allows me to have the app run in the background in as many circumstances as possible.
What are my options here?

It is not possible to run a terminated app with Swift. Once an app has been terminated, it is no longer running and cannot be restarted. The only way to run the app again is to open it from the device's home screen or app launcher.

Related

Does Flutter Background Fetch work on iOS when the app is terminated?

I'm building a Flutter app and need to call a function every day (to schedule some notifications). I came across the flutter_background_fetch package, which seems to be a perfect solution for Android, since the main limitation of the minimum 15 minute interval is not a problem.
However, I am supremely confused about how well the package works for iOS. According to the README, "When your app is terminated, iOS no longer fires events". However, I've also seen posts on Stackoverflow that claim that iOS Background App Refresh periodically relaunches your app to run background fetches (and posts that say it is unreliable or doesn't work at all).
So does flutter_background_fetch work on iOS when the app is terminated (eg. double tap home and swipe up)?
Edit: Also exploring flutter_workmanager, which seems promising.
There is no perfect Dart solution for iOS to schedule background task as android when app terminate, in android we can use Alarm Manager
But you can try native side implementation with BGTaskScheduler
https://github.com/fluttercommunity/flutter_workmanager

Program an iOS app to launch itself at specific times

I'm developing a medical alert and record keeping app for iOS for a client. The app needs to be able to open itself at specific times based on a schedule that is set remotely.
I've searched around for how this can be done, and I keep running into other apps that let you schedule app launch times, but this needs to be a self contained solution.
I'd rather not JailBreak the iOS device to make it work, and I've come across articles that say iOS 9+ now has this capacity, but no instructions on how to make it come about.
Any clues, tutorials, or other information on how to accomplish this?
You can use "silent" push notifications (with "content-available") on iOS 7+ to launch the app when the push notification is received on the device. You will get a chance to process the notification, and the app will be launched if it's not already running.
However, it still won't work if the user has force killed the app.
Also, iOS will not launch your app if it feels you've gone over the daily processing time or data quota.

How to avoid iOS app being terminated by system too often when in background

I'm building an iOS app for iOS 8 & 9 and I am facing the problem that when the app goes to background the system is terminating it after just 2 or 3 minutes.
My testing is easy:
I kill all running apps from my iPhone.
I restart my iPhone (to ensure no other apps are taking memory).
I launch my app.
I do nothing inside my app.
I press the "Home" button, moving my app to background.
I wait doing nothing else for 2 or 3 minutes.
I open my app again and surprise, the system has terminated it and now it is restarting as a new launch.
Some comments:
The app does not use CoreLocation in background neither any other service.
I've profiled the app, trying to understand if it is consuming too much memory. When moving to background, it consumes around 25Mb of RAM memory. I'm attaching a screenshot below.
This behavior has been tested on iPhone 5, 5s, 6, 6+.
In iPhone 6s and 6s+ seems to take a bit more time to happen, but still happens.
My question is: Do you know why would this be happening? anything I might not be considering or just forgetting?
I don't want to force my app to run in background by using CoreLocation or something similar. And I'm ok if the system kills my app eventually. What I don't want is that everytime I move my app to background the system terminates it.
Any hint or help will be appreciated.
Thanks,
All applications are automatically killed by the system
According the Apple documentation:
App Termination
Apps must be prepared for termination to happen at any time and should not >wait to save user data or perform other critical tasks. System-initiated >termination is a normal part of an app’s life cycle. The system usually >terminates apps so that it can reclaim memory and make room for other apps >being launched by the user, but the system may also terminate apps that >are misbehaving or not responding to events in a timely manner.
Suspended apps receive no notification when they are terminated; the >system kills the process and reclaims the corresponding memory. If an app >is currently running in the background and not suspended, the system calls >the applicationWillTerminate: of its app delegate prior to termination. >The system does not call this method when the device reboots.
In addition to the system terminating your app, the user can terminate >your app explicitly using the multitasking UI. User-initiated termination >has the same effect as terminating a suspended app. The app’s process is >killed and no notification is sent to the app.
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html#//apple_ref/doc/uid/TP40007072-CH2-SW1
You can track position but you will certainly see a blue status bar to indicate that an application use GPS tracking.
Maybe you can try to "wake up" your app in background with silent notification...
If it is not necessary to keep your app alive, trust the system...
Some error in inside your code. Please select debug Navigator before run your app... Now you can able to find your error..
Or too much memory also it will terminated..
Apps which are running in the background drain battery life faster, It gives you a bad perception of the device, instead of the app, because the average consumer has no idea that it's an app draining battery.
Thus iOS won't allow your app to run in the background, more than a few seconds. But there are some exception, an app can request extension to this by declaring that its starting a Background Task.
for more info you can check below links:
http://blog.dkaminsky.info/2013/01/27/keep-your-ios-app-running-in-background-forever/
http://www.speirs.org/blog/2012/1/2/misconceptions-about-ios-multitasking.html

IOS limitations when running on background

I searched informations about possibilities when running an iOS app on background, but I didn't found same on different sites.
My application has to read the battery level (with step of 1%) and the time, but I don't know if I can read that when running on background.
Please if someone is sure about it or know a site to read these infos, it will be very nice.
EDIT : I've one more question, can I just open my app (to perform more actions) when the notification center return a battery state under 5% for example ?
No, you can't.
It's not possible to let your app running on background, it's iOS system's limitations.
In iOS 7.0 and later, you have opportunity to do some pre-fetch stuff even your app is not running, through the method like application:performFetchWithCompletionHandler:, but you should tell the device by posting remote notification from your server.

IOS 5 Application running in the background terminates after 4 days

I am running an app in the background with significant location change and monitor regions, the app works well but if the user don't use the app for a couple of days then the app gets terminated. Is there a way to prevent the app from being terminated ? like maybe triggering an alert to remind the user to open the app every 2 days ? does anyone knows how to get the app to run continually, and not to be terminated/suspended ?
"significant location changes" over 4 days means your app is not only draining the battery (a no-no since iOS 4.x), but it is taking resources away from the system in the background. Apps cannot process forever in the background, so the OS makes the choice to kill it. Just turn off background processing and only update the user's location when they open the app. And do you want to know the best part: It's all fairly random! The OS could have killed Mail or YouTube or some such other app to make room for yours, but it didn't, it killed your app. There is no documented way around it, sorry.
I think it is not possible for an app to run continuously, and not to be terminated/suspended. You can use push notification to remind user to open app in every two days.

Resources