2

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?

objectivecdeveloper
  • 1,050
  • 11
  • 29
  • Why would you like to distinct these 2 behaviors? Tell something more about your requirement, maybe we can have some other solutions to your **real** problem. – Tonny Xu Feb 03 '12 at 13:56
  • Actually I've to load login screen again when the device goes in lock mode. And by any other way App goes in background then have to do nothing. – objectivecdeveloper Feb 04 '12 at 07:23

2 Answers2

3

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.

Tonny Xu
  • 2,162
  • 2
  • 16
  • 20
1

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

Community
  • 1
  • 1
Eric
  • 2,045
  • 17
  • 24