3 回答

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
喚醒時(shí)即重新啟動(dòng)應(yīng)用程序(通過(guò)跳板,應(yīng)用程序切換或URL)applicationWillEnterForeground:
。在應(yīng)用程序準(zhǔn)備就緒后,僅在后臺(tái)運(yùn)行后才執(zhí)行一次,而applicationDidBecomeActive:
在啟動(dòng)后可能會(huì)被多次調(diào)用。這applicationWillEnterForeground:
對(duì)于重新啟動(dòng)后只需進(jìn)行一次設(shè)置的理想選擇。
applicationWillEnterForeground:
叫做:
重新啟動(dòng)應(yīng)用程序時(shí)
之前
applicationDidBecomeActive:
applicationDidBecomeActive:
叫做:
應(yīng)用首次啟動(dòng)后的時(shí)間
application:didFinishLaunchingWithOptions:
后
applicationWillEnterForeground:
如果沒(méi)有URL處理。之后
application:handleOpenURL:
被稱為。之后
applicationWillResignActive:
,如果用戶忽略中斷就像一個(gè)電話或短信。
applicationWillResignActive:
叫做:
當(dāng)有電話之類的干擾時(shí)。
如果用戶接聽(tīng)電話
applicationDidEnterBackground:
被呼叫。如果用戶忽略呼叫
applicationDidBecomeActive:
被調(diào)用。當(dāng)按下主屏幕按鈕或用戶切換應(yīng)用程序時(shí)。
文檔說(shuō)你應(yīng)該
暫停正在進(jìn)行的任務(wù)
禁用計(jì)時(shí)器
暫停游戲
降低OpenGL幀率
applicationDidEnterBackground:
叫做:
后
applicationWillResignActive:
文檔說(shuō)您應(yīng)該:
釋放共享資源
保存用戶數(shù)據(jù)
使計(jì)時(shí)器無(wú)效
保存應(yīng)用程序狀態(tài),以便在應(yīng)用程序終止時(shí)可以將其恢復(fù)。
禁用UI更新
您有5秒的時(shí)間做您需要做的事情并返回方法
如果您未在約5秒鐘內(nèi)返回,則該應(yīng)用程序?qū)⒔K止。
您可以要求更多時(shí)間
beginBackgroundTaskWithExpirationHandler:

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
管理應(yīng)用程序的生命周期有助于解決您的問(wèn)題。有關(guān)快速概念,您可以參閱該文檔中的圖。您還可以從XCode向?qū)傻拇a中讀取注釋。列出如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (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)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the active state;
here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
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.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}
有關(guān)更多詳細(xì)說(shuō)明,請(qǐng)參閱UIApplicationDelegate的官方文檔。

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
我仍然對(duì)Dano的回答有些困惑,因此我做了一些測(cè)試以獲取某些情況下的事件流以供參考,但是它對(duì)您也可能有用。這適用UIApplicationExitsOnSuspend于不在info.plist中使用的應(yīng)用。這是在iOS 8模擬器上進(jìn)行的,并已通過(guò)iOS 7設(shè)備確認(rèn)。請(qǐng)?jiān)廥amarin的事件處理程序名稱。它們非常相似。
從非運(yùn)行狀態(tài)進(jìn)行的初始啟動(dòng)和所有后續(xù)啟動(dòng):
完成啟動(dòng)
激活
中斷(電話,頂部向下滑動(dòng),底部向上滑動(dòng)):
主頁(yè)按鈕雙擊列出不活動(dòng)的應(yīng)用程序,然后重新選擇我們的應(yīng)用程序:
OnResignActivation
激活
主頁(yè)按鈕連按兩次列出不活動(dòng)的應(yīng)用程序,選擇另一個(gè)應(yīng)用程序,然后重新啟動(dòng)我們的應(yīng)用程序:
按下主頁(yè)按鈕,然后重新啟動(dòng):
鎖定(開/關(guān)按鈕),然后解鎖:
OnResignActivation
DidEnterBackground
進(jìn)入前景
激活
雙擊主屏幕按鈕,然后終止我們的應(yīng)用程序:(隨后的重新啟動(dòng)是第一種情況)
OnResignActivation
DidEnterBackground
DidEnterBackground(僅限iOS 7?)
是的,DidEnterBackground在iOS7設(shè)備上被兩次調(diào)用。兩次UIApplication狀態(tài)均為Background。但是,iOS 8模擬器沒(méi)有。這需要在iO
- 3 回答
- 0 關(guān)注
- 1789 瀏覽
添加回答
舉報(bào)