iOS how to detect when app was removed from process

后端 未结 4 1712
感动是毒
感动是毒 2020-11-28 14:57

What is the delegate method for detecting when application was closed.

I mean when user tap this button:

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 15:46

    You can implement the -applicationWillTerminate: method of your UIApplicationDelegate delegate to respond to termination events. However, it's not guaranteed to be called in all cases, so you should not rely on it being called. According to the iOS App Programming Guide:

    If your app is running (either in the foreground or background) at termination time, the system calls your app delegate’s applicationWillTerminate: method so that you can perform any required cleanup. You can use this method to save user data or app state information that you would use to restore your app to its current state on a subsequent launch. Your method has approximately 5 seconds to perform any tasks and return. If it does not return in time, the app is killed and removed from memory.

    Important: The applicationWillTerminate: method is not called if your app is currently suspended.

提交回复
热议问题