請檢查該瞭解的iOS應用程序生命週期是如何工作 - https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html
現在,在你的項目中發現這下面的方法來跟蹤應用程序的生命週期過程。
對於目標C
- (void)applicationWillResignActive:(UIApplication *)application{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillTerminate:(UIApplication *)application{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
}
爲SWIFT(3.0)
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
}
希望這有助於。
沒有意外關閉應用程序這樣的事情。在後臺應用程序被殺害是正常的。你的應用應該正確處理這個。向用戶顯示這樣的消息是沒有意義的。 – rmaddy
'我想告訴用戶一個消息,比如「這個應用程序沒有上次正確關閉」。 - 這是違反Apple的做法......使用最近的列表**關閉應用程序是**正確的方式關閉iOS上的應用程序 –
@MihaiFratu是的..我同意你的看法,但也有關閉應用程序的另一種可能性..我們如何管理該應用程序 – Saranjith