0

On Android, services give us the flexibility to continue to run code even when the app is not running in the background, as the service continues to execute even if the app that started the service is terminated.

I am looking to do the same on iOS. I know backgroundFetch but it works only when the app is in the background.

Diamond
  • 7,428
  • 22
  • 37
vipul bansal
  • 13
  • 1
  • 7
  • Apple is not providing like this, You can only call service when app is background. When your app is not running or terminated then you can do nothing to run service – Jitendra Modi Feb 15 '17 at 05:48
  • Are you sure. Aint there any alternate. May be some third party code. – vipul bansal Feb 15 '17 at 05:58
  • I am sure there won't be anything that could help you running service when your app is not running or terminated. See my question and answer by users http://stackoverflow.com/questions/39720213/increase-badge-count-from-client-side-not-from-payload-receive-count – Jitendra Modi Feb 15 '17 at 06:01

1 Answers1

1

You can't run any code when the app is terminated in iOS as given in the documentation.

You can do something before the app is going to get terminated by using the following ways.

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

or by registering a notification anywhere in app

NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationWillTerminate, object: nil, queue: OperationQueue.main) { (notification) in

}
KrishnaCA
  • 5,615
  • 1
  • 21
  • 31