2016-03-07 49 views
0

我正在嘗試實現此功能。當用戶按回家按鈕時,應用程序將轉到後臺(它仍將運行),當他再次打開時,應用程序不會從最後一個視圖開始,而是從一開始。在其開始狀態下從後臺重新啓動應用程序

如何檢測應用程序後臺並重置它以開始查看。我認爲它應該是應用程序代表 謝謝你的所有意見,但那只是答案的1/2。如何從應用程序委託poptorootvc?

+0

每次你想進入的背景下,殺了你的應用程序? – Tinyfool

+0

不殺,只需按一次主頁按鈕....暫停應用程序 –

+0

我錯過了這裏的一個問題 –

回答

2

我認爲這是你在找什麼

func applicationDidBecomeActive(application: UIApplication) { 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
} 

在你的AppDelegate將這個,只是切換到要在此功能的任何觀點。

或者,你可以使用的檢測應用程序狀態的變化,這些其他的AppDelegate功能之一

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. 
} 

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. 
} 
2

你可以把你的代碼在

func applicationWillEnterForeground(application: UIApplication) { 

} 
相關問題