• iOS 锁屏判断


    iOS 锁屏判断

     

    应用程序的单例类对象中得到应用程序委托的对象 

    UIApplicationDelegate* myDelegate = [[UIApplication sharedApplication] delegate];

     

    UIApplication 接收到所有的系统事件和生命周期事件时,都会把事件传递给UIApplicationDelegate进行处理,对于用户输入事件,则传递给相应的目标对象去处理。

     

    - (void)applicationWillResignActive:(UIApplication *)application 

       通知委托应用程序将进入非活动状态,在此期间,应用程序不接收消息或事件。

    这个方法在用户锁住屏幕时,也会调用。

     

    与之相适应的是应用程序重新被用户打开时的委托 方法。另外常用的就是内存不足的系统警告,此时会调用应用程序委托类的applicationDidReceiveMemoryWarning()方法, 然后我们就可以试着释放一些内存了。

     

     

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, updateEnabled, CFSTR("com.apple.iokit.hid.displayStatus"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

        

        // 1状态

        CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, lockComplete, CFSTR("com.apple.springboard.lockcomplete"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

        // 2状态

        CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, lockState, CFSTR("com.apple.springboard.lockstate"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);

     

     

    static void updateEnabled(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo) {

        uint64_t state;

        int token;

        notify_register_check("com.apple.iokit.hid.displayStatus", &token);

        notify_get_state(token, &state);

        notify_cancel(token);

        NSLog(@"锁屏状态:%llu",state);

    }

     

    static void lockComplete(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo) {

        uint64_t state;

        int token;

        notify_register_check("com.apple.springboard.lockcomplete", &token);

        notify_get_state(token, &state);

        notify_cancel(token);

        NSLog(@"lockComplete状态:%llu",state);

    }

     

    static void lockState(CFNotificationCenterRef center, void* observer, CFStringRef name, const void* object, CFDictionaryRef userInfo) {

        uint64_t state;

        int token;

        notify_register_check("com.apple.springboard.lockstate", &token);

        notify_get_state(token, &state);

        notify_cancel(token);

        NSLog(@"lockState状态:%llu",state);

    }

  • 相关阅读:
    (ubuntu ufw)My firewall is blocking network connections from the docker container to outside
    nginx repos
    Xvfb新建虚拟X窗口,通过x11vnc启动VNC Server并转发Xvfb启动的虚拟窗口
    xdotool xdotool模拟击键和鼠标移动--CutyCapt是一个截图工具,xvfb-run
    zabbix debug and vulnerability https://www.zabbix.com/documentation/3.0/manual/concepts/sender
    初探 Nginx 架构
    Nginx缓存
    Nginx代理功能与负载均衡详解
    CentOS 7 部署 nginx-1.14.2
    LDAP第三天 MySQL+LDAP 安装
  • 原文地址:https://www.cnblogs.com/pocket-mood/p/4482833.html
Copyright © 2020-2023  润新知