sleep mode vs notification center open
-
04-12-2019 - |
Frage
in both, 1) iPhone goes in Sleep mode 2) Open notification Center
It calls
- (void)applicationWillResignActive:(UIApplication *)application
Is there any way to identify if this method is called because device went in to sleep mode or by opening notification center?
Lösung
There are some hacks to detect lock/unlock, but nothing official that couldn't break with a future iOS release.
Andere Tipps
OK, When you lock your screen/iPhone goes to sleep mode, the front most app(Your app) will go to background mode, and when you pull down the Notification Center, you app actually is not pushed to background.
So, you can use
- (void)applicationWillEnterForeground:(UIApplication *)application
or
- (void)applicationDidEnterBackground:(UIApplication *)application
to set a value, say bgFlag
, in your app delegate class,
then, when - (void)applicationDidBecomeActive:(UIApplication *)application
is invoked, you check whether bgFlag
is set or not.
Good luck.