开发者

Get Notification when My device get auto locked

Can i get notification in my running app when device get auto locked?

any开发者_开发知识库 help ?


You could use

- (void)applicationWillResignActive:(UIApplication *)application;

It will be sent to your app if the user hits the lock button, goes to sleep mode automatically or swithes to another app on multitasking phones.

Here is a good UIApplication delegate overview, covers this subject and a handful more you might run into.


Yes, you always get this notification, just watch:

- (void)applicationWillResignActive:(UIApplication *)application;


There is not explicit notification for that afaik. The applicationWillResignActive will be called, but it will also be called when the app goes into the background through other means (like hitting HOME button, or switching to another app).


Execute this code to get the state in applicationWillResignActive

 int notify_token;
 notify_register_dispatch("com.apple.springboard.lockstate", &notify_token,dispatch_get_main_queue(), ^(int token) {
 uint64_t state = UINT64_MAX;
 notify_get_state(token, &state); 
 if(state == 0) {
 NSLog(@"unlock device");
 } else {
 NSLog(@"lock device");
 }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜