detect lockstate and displaystate

- (void)registerAppforDetectLockState {
    
    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");
        }
        
        NSLog(@"com.apple.springboard.lockstate = %llu", state);
//        UILocalNotification *notification = [[UILocalNotification alloc]init];
//        notification.repeatInterval = NSCalendarUnitDay;
//        [notification setAlertBody:@"Hello world!! I come becoz you lock/unlock your device :)"];
//        notification.alertAction = @"View";
//        notification.alertAction = @"Yes";
//        [notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:1]];
//        notification.soundName = UILocalNotificationDefaultSoundName;
//        [notification setTimeZone:[NSTimeZone  defaultTimeZone]];
//        
//        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
        
    });
}

需要

#import <notify.h>

另外三个系统通知

"com.apple.iokit.hid.displayStatus"
"com.apple.springboard.hasBlankedScreen"
"com.apple.springboard.lockcomplete"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,584评论 25 709
  • 点击查看原文 Web SDK 开发手册 SDK 概述 网易云信 SDK 为 Web 应用提供一个完善的 IM 系统...
    layjoy阅读 14,032评论 0 15
  • 损失三颗牙是我人生中第二次严重受伤;第一次严重受伤,要追溯到一九九五年。晚饭之前,我还惦记着那天刚刚发现的一台压面...
    林蛋大阅读 323评论 0 0
  • 今天是2016年1月7日,星期四。 目前团队成员11人,包括: 首席吉祥物:道哥 策划:神经刀lj UI:花花 i...
    捍道89阅读 185评论 0 0
  • 最近看到一篇万维钢老师的文章,讨论的是学校教育的问题。有一个科学研究表明,学生的考试成绩和学生对学校的态度之间,没...
    灵小猫阅读 839评论 1 1