sleep mode vs notification center open

旧街凉风 提交于 2019-12-24 00:44:47

问题


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?


回答1:


There are some hacks to detect lock/unlock, but nothing official that couldn't break with a future iOS release.




回答2:


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.



来源:https://stackoverflow.com/questions/9060066/sleep-mode-vs-notification-center-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!