强制锁定屏幕 [英] Force lock screen

查看:170
本文介绍了强制锁定屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在给定的时间段后自动锁定设备。我唯一能做到这一点就是这样做:

  func application(应用程序:UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) - > Bool {
//在应用程序启动后覆盖自定义点。

UIApplication.sharedApplication()。idleTimerDisabled = true

NSTimer.scheduledTimerWithTimeInterval(30,target:self,selector:lockScreen,userInfo:nil,repeats:false)

返回true
}

func lockScreen(){
print(锁定屏幕)
UIApplication.sharedApplication()。idleTimerDisabled = false
}

但它似乎不起作用。还有其他选择吗?市场上有一款名为



我也看到过使用私有框架这肯定会要求拒绝:

  char * gsDylib =/ System / Library / VariousFrameworks / GraphicsServices.framework / GraphicsServices ; 
void * handle = dlopen(gsDylib,RTLD_NOW);
if(handle){
BOOL locked = FALSE;
void(* _GSEventLockDevice)()= dlsym(handle,GSEventLockDevice);
if(_GSEventLockDevice){
_GSEventLockDevice();
// ... ...
}
dlclose(句柄);
// ...
}

首次启动应用时,他们会问允许:




  • 即使不使用应用程序,也可以将数据提供给蓝牙设备

  • 发送推送通知

  • 访问联系人

  • 访问麦克风

  • 即使不使用应用程序也使用位置



我不知道这些框架中的任何一个是否能让你锁定屏幕,但也许?...






快速更新:



经过更多研究来自



从我所知道的(我不是这方面的专家),是触发锁定,它发送的只是一个鼠标事件,所有事件数据都被清零。没有按下任何按钮。我的目标是在Arduino上复制这个......所以还有更多的工作要做。

解决方案

如果你想知道他们是怎么做的:



该手机与其硬件中包含的蓝牙设备配对。
如果你进一步检查,你会发现这个蓝牙设备有键盘配置文件:只需检查你的手机,你会看到它被识别为无线键盘......有趣......你看到了吗?答案来了吗? ...



你打赌!设备向手机发送锁定屏幕命令键,就好像它是连接的蓝牙键盘一样(是的,因为BT键盘实际上可以这样做)。你去吧。



===编辑===



请看看这个 HID使用表,您将找到一些有用的命令代码。我们正在寻找的关键代码很可能是 0x81 0x82


I'm trying to auto lock the device after a given time period. The only thing I've seen that would make this possible is doing this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    UIApplication.sharedApplication().idleTimerDisabled = true

    NSTimer.scheduledTimerWithTimeInterval(30, target: self, selector: "lockScreen", userInfo: nil, repeats: false)

    return true
}

func lockScreen() {
    print("locking screen")
    UIApplication.sharedApplication().idleTimerDisabled = false
}

However it doesn't seem to work. Are there any other alternatives? There is app on the market called CellControl that does this so I know it's possible, just can't seem to figure out how.

I've also tried in obj-c taken from this answer

Here is a clip of their app working which is downloaded from the public app store. You can see that as soon as I hit the home button and exit the app, they force lock the screen.

I've also seen using private frameworks which would most definitely call for rejection:

char *gsDylib = "/System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices";
void *handle = dlopen(gsDylib, RTLD_NOW);
if (handle) {
  BOOL locked = FALSE;
  void (*_GSEventLockDevice)() = dlsym(handle, "GSEventLockDevice");
  if (_GSEventLockDevice)  {
    _GSEventLockDevice();
    //...
  }
  dlclose(handle);
  //...
}

When first launching the app they ask for permission to:

  • Make data available to bluetooth devices even when not using the app
  • Send push notifications
  • Access contacts
  • Access microphone
  • Use location even when not using the app

I don't know if any of these frameworks would give you the ability to lock the screen but maybe?...


Quick update:

After some more research and huge help from JBA I'm getting closer to a solution. It seems that Cell Control is acting as keyboard peripheral allowing them to send a command to lock the screen. So I bought a bluetooth keyboard to try and guess what...works like charm. I'm able to lock and unlock my device from it. So I hooked the keyboard up to my mac (via Bluetooth) to sniff the packets. This event is logged when the lock button is pressed on the keyboard:

From what I can tell (I'm by no means an expert at this), is that to trigger a lock, all it sends is a mouse event with all event data zero'd out. Along with no buttons pressed either. My goal to replicate this on Arduino...so more work to be done.

解决方案

If you want to know how they do this :

The phone is paired with the bluetooth device included in their hardware. If you check further, you will notice that this Bluetooth device has the "Keyboard" profile: just check on your phone, you will see it is recognized as a wireless keyboard... Interesting... Do you see the answer coming ? ...

You Bet ! The device sends to the phone the lock screen command-key as if it was a connected bluetooth keyboard (yes, because a BT Keyboard can actually do this). And here you go.

=== EDIT ===

Please take a look at this HID usage table, you will find some useful command codes. The key codes we're looking for are most probably 0x81 or 0x82.

这篇关于强制锁定屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆