是否有知道WillResignActive是由於將應用程序移至背景還是由於打開控制/消息中心?知道如果應用程序在WillResignActive中移動到背景?
1
A
回答
0
如果您的應用已移至後臺,則還會發送DidEnterBackground
消息。您可以在WillResignActive
之後的一小段延遲後檢查是否發送了兩封郵件。
編輯:選中該代碼
@interface HSAppDelegate()
{
BOOL _enteredBackground;
}
@end
@implementation HSAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"%s", __PRETTY_FUNCTION__);
_enteredBackground = NO;
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.rootViewController = [HSViewController new];
[_window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
NSLog(@"%s", __PRETTY_FUNCTION__);
dispatch_async(dispatch_get_main_queue(), ^{
if (!_enteredBackground)
{
// Do whatever you want here.
}
else
{
// This won't get called until the app comes back to foreground.
}
});
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSLog(@"%s", __PRETTY_FUNCTION__);
_enteredBackground = YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSLog(@"%s", __PRETTY_FUNCTION__);
_enteredBackground = NO;
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}
@end
+0
謝謝。關鍵是我需要在WillResignActive中執行操作,我不能等待DidEnterBackground。 – shannoga
+0
我已經爲你添加了示例代碼。希望它能幫助你指出正確的方向。它工作的原因是在同一隊列中調用'dispatch_async'會強制該塊被調用而不是下一個運行循環。 –
相關問題
- 1. 如何從應用程序中刪除背景知道?
- 2. 的Android - 檢測應用程序移動到背景和前景
- 3. 通過PhoneGap將應用程序移動到iPhone上的背景
- 4. Android應用程序移動到背景而沒有崩潰
- 5. Cocos2D,塊和將應用程序移動到背景
- 6. iOS Swift將應用程序移動到背景
- 7. 如何知道我的應用程序是否回到了背景
- 8. 如何檢測推送通知,如果應用程序在iOS應用程序中的背景?
- 9. 如何知道我們的應用程序已經在Android的背景
- 10. 用滾動效果移動背景
- 11. 如何禁用移動web應用程序中的背景div的滾動
- 12. 在應用程序中調用背景
- 13. 將控制檯應用程序移動到用戶選擇的背景中
- 14. 在Ionic 2應用程序中接收OneSignal背景通知
- 15. 如果應用程序轉到背景,UIView動畫不起作用
- 16. 如何在離子2中將應用程序從背景應用到前景?
- 17. 重新啓動應用程序從背景到前景
- 18. 啓動「背景」Windows應用程序
- 19. Tizen應用程序振動背景
- 20. 鈦移動應用程序崩潰的背景(包括服務)
- 21. 移動iPhone應用程序背景圖像
- 22. MVC4移動應用程序背景圖像
- 23. 如何在Android應用程序中創建滾動背景?
- 24. iPhone - 在應用程序啓動過程中,應用程序進入背景
- 25. android sdk。 startActivity()移動編程。到背景
- 26. 如何使修補程序背景移動到龜後面?
- 27. 如何在ios中使用陀螺儀應用3D移動背景效果
- 28. 如何在C編程動畫背景應用程序#
- 29. Android應用程序背景
- 30. Android背景應用程序
你的問題還不清楚。您是否問我們是否知道該應用因爲進入後臺或控制中心是否打開而辭職? –
感謝您指出這一點,編輯問題 – shannoga