开发者

Is there a way to know when an iOS device locks/unlocks?

I need to be able to perform som开发者_Go百科e actions when the user unlocks the screen (namely they need to log-in again). I checked the UIApplicationDelegate protocol thinking it was a logical place for such an interface, but didn't see anything that seemed to do this. Is this even possible?

Edit:

applicationDidBecomeActive: and applicationDidEnterBackground: look like they may get triggered for unlocking and locking, but the documentation doesn't mention it specifically.


You can use applicationDidBecomeActive and applicationWillResignActive this will tell you any time the app is slept, this includes locking the phone, and things like phone calls.

applicationDidBecomeActive:

This method is called to let your application know that it moved from the inactive to active state. This can occur because your application was launched by the user or the system. Applications can also return to the active state if the user chooses to ignore an interruption (such as an incoming phone call or SMS message) that sent the application temporarily to the inactive state.

applicationWillResignActive:

This method is called to let your application know that it is about to move from the active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. An application in the inactive state continues to run but does not dispatch incoming events to responders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜