我需要在applicationDidEnterBackground
中執行某些操作。但我需要區分哪些用戶操作導致「輸入背景」:屏幕鎖定或主頁按鈕按下。在iOS7上區分屏幕鎖定和主屏幕按鈕
我使用這個代碼,這是從這個post - How to differentiate between screen lock and home button press on iOS5?:
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
NSLog(@"Sent to background by locking screen");
} else if (state == UIApplicationStateBackground) {
NSLog(@"Sent to background by home button/switching to other app");
}
它工作正常,在iOS6的。但在iOS7(包括設備和模擬器)上,我總是得到UIApplicationStateBackground
,無論用戶是單擊home還是鎖定按鈕。
有人有什麼可能導致這種情況的想法嗎? iOS 7更新到多任務後臺處理?或者我的應用程序的某些設置(我的應用程序的背景模式關閉)?
是否有替代解決方案?
可能的重複[如何區分screen loc k和主頁按鈕在iOS5上按?](http://stackoverflow.com/questions/8303703/how-to-differentiate-between-screen-lock-and-home-button-press-on-ios5) – jmort253
我想我沒有說清楚。我在鏈接上閱讀了這篇文章,但這在iOS7中不再適用。我不認爲這是重複的。但無論如何,我編輯我的問題來說清楚。 – Perisheroy
好主意澄清,再加上編輯顛倒你的帖子回到頂部,讓其他人再次看到它。 :D – jmort253