2

I am trying to remove data from a Firebase database that I have set up when a user closes an app. Is there a method that is called when the app is closed in order for me to call one last function to remove the data from the database?

Thanks

AL.
  • 36,815
  • 10
  • 142
  • 281
Mitch Kelly
  • 481
  • 3
  • 10
  • To Close application using double time press home button and swipe Up is different thing and press home button and application will work on background is different task. Maybe you are looking for `- (void)applicationDidEnterBackground:(UIApplication *)application` method – ChintaN -Maddy- Ramani Jun 01 '17 at 04:54
  • I am looking for a method that will be called when the home button is double tapped and then the app is swiped up – Mitch Kelly Jun 01 '17 at 04:55
  • Check https://stackoverflow.com/questions/10200505/which-function-is-called-when-iphone-app-is-terminated – ChintaN -Maddy- Ramani Jun 01 '17 at 05:03
  • 1
    Looks like first you tap home button single time and then press home button twice and kill app. In that case `applicationWillTerminate` will not be called as app is in suspended state. It will call when your app is open and double press home button and kill your app. – ChintaN -Maddy- Ramani Jun 01 '17 at 05:05

3 Answers3

5

To Close application using double time press home button and swipe Up is different thing. It will call below method

- (void)applicationWillTerminate:(UIApplication *)application {
}

Press home button and application will work on background is different task. Maybe you are looking for

- (void)applicationDidEnterBackground:(UIApplication *)application{
}

Please refer TheAppLifeCycle

  1. application:willFinishLaunchingWithOptions:—This method is your app’s first chance to execute code at launch time.

  2. application:didFinishLaunchingWithOptions:—This method allows you to perform any final initialization before your app is displayed to the user.

  3. applicationDidBecomeActive:—Lets your app know that it is about to become the foreground app. Use this method for any last minute preparation.

  4. applicationWillResignActive:—Lets you know that your app is transitioning away from being the foreground app. Use this method to put your app into a quiescent state.

  5. applicationDidEnterBackground:—Lets you know that your app is now running in the background and may be suspended at any time.

  6. applicationWillEnterForeground:—Lets you know that your app is moving out of the background and back into the foreground, but that it is not yet active.

  7. applicationWillTerminate:—Lets you know that your app is being terminated. This method is not called if your app is suspended.

Hope it will help you.

ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48
1

use this appdelegate method

- (void)applicationWillTerminate:(UIApplication *)application {
}

Or erase data in Every application launch, because applicationWillTerminate only get called in restricted conditions.

Ajjjjjjjj
  • 669
  • 4
  • 12
0

Firebase supports some functions regarding presence.

https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRDatabaseReference#/c:objc(cs)FIRDatabaseReference(im)onDisconnectRemoveValue

If you want to remove a node on disconnect. ref.onDisconnectRemoveValue()

Or if you want to set a value on a node: ref.onDisconnectSetValue(someValue)

Tony Nguyen
  • 491
  • 3
  • 7