1

I want to kill my application if it is in the suspended mode for more than 30mins so that when it relaunches it fetches new data. I have looked all over but wasn't able to find a solution to it. If anyone can recommend something it will be a huge help.

exit(0)

This above command is not recommended and apple will reject the application. Then there is the functionality of BGAppRefreshTask for iOS13 and above or minimumBackgroundFetchInterval for iOS less than iOS13, but still how to actually kill the application programmatically? Any help would be such a plus. Thanks

Mohsin Khubaib Ahmed
  • 1,008
  • 16
  • 32
  • I do recommend that instead you should aim at some kind of app state relaunch without resorting to killing the process if the right conditions are met. – Kamil.S Jul 12 '20 at 14:55
  • @Kamil.S Erm, I dont quite understand what you're saying.. umm can u suggest how? – Mohsin Khubaib Ahmed Jul 12 '20 at 15:30
  • 1
    Obviously I don't know what your app exactly does. But very vaguely - detect the condition upon foregrounding the app and if it's met do the steps the app would normally do upon a cold launch. Additionally reset the screen navigation stack and do whatever you do for fetching data to make the app state fully functional again. – Kamil.S Jul 12 '20 at 16:41
  • Oh that i know ofcourse, I just thought theres a way of actually killing the app starting afresh.. however what you're suggesting is that whenever the app is suspended, i kick off with a timer, e.g. if the timer has gone till 20mins, i reset the rootviewcontroller to the initialviewcontroller and re fetch the data.. hmm thats kind of doable as well.. however what do you think about this? https://stackoverflow.com/a/52515554/3359372 – Mohsin Khubaib Ahmed Jul 12 '20 at 21:12
  • 1
    You'd have to measure time upon backgrounding and foregrounding and calculate at the difference as `dispatchAfter` won't give you the result you expect while app is in background. If you don't care about user setting date manually on the device in between you can use `Date`. To be extra secure you can rely instead on https://stackoverflow.com/questions/36203662/getting-system-uptime-in-ios-swift – Kamil.S Jul 13 '20 at 05:19

0 Answers0