Forced Lock Screen

I try to automatically lock the device after a specified period of time. The only thing I saw to do this was to do the following:

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 does not work. Are there any other alternatives? There is an application on the market called CellControl that does this so that I know that it is possible, it just cannot seem to figure it out.

I also tried in obj-c taken from this answer

Here is the clip for their app, which is downloaded from the public app store. You can see that as soon as I press the home button and exit the application, they will lock the screen.

enter image description here

I also saw the use of private frameworks that would most definitely require 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 you first start the application, they request permission to:

  • Make data available for Bluetooth devices even if you are not using the application
  • Send push notifications
  • Access to Contacts
  • Microphone access
  • Use location even if it is not in use.

I don’t know if any of these frameworks will provide the ability to lock the screen, but maybe? ...


Quick update:

After some research and a lot of help from JBA, I'm getting closer to a solution. Cell Control seems to act as a peripheral device for the keyboard, allowing them to send a command to lock the screen. So I bought a Bluetooth keyboard to try and guess what ... works like a charm. I can lock and unlock my device. So I connected the keyboard to my mac (via Bluetooth) to sniff the packets. This event is logged when the lock button on the keyboard is pressed:

enter image description here

From what I can say (I am by no means an expert on this), is that to trigger a lock, all that it sends is a mouse event when all the data about the events is missing. Along with buttons not pressed. My goal is to repeat this on the Arduino ... so much work remains to be done.

+6
source share
3 answers

If you want to know how they do it:

The phone is connected to a Bluetooth device included in their hardware. If you continue checking, you will notice that this Bluetooth device has a “Keyboard” profile: just check on your phone, you will see that it is recognized as a wireless keyboard ... Interesting ... Do you see the answer? ...

You put! The device sends a command key to the phone on the lock screen, as if it were a connected Bluetooth keyboard (yes, because the BT-keyboard can actually do this). And here you are.

=== EDIT ===

Please look at this HID usage table ; you will find some useful command codes. The key codes we are looking for are most likely 0x81 or 0x82 .

+8
source

After contacting Apple Developer Technical Support, there is no supported way to achieve this functionality without using private APIs. Using these options will lead to a rejection of your application.

I assume that CellControl was able to do this through a review, because the only way to use this function is to install your equipment in your car, the device paired with it and start moving. I assume that during the app review, Apple did not buy one of its devices and actually tested it. Although I always had the impression that they are scanning your binaries to verify the use of undocumented APIs, but this seems wrong.

Another possibility mentioned by @Chris is that they could have an agreement with Apple before starting development. Although this seems unlikely, it is possible.

Here are some excerpts from Apple Developer Technical Support:

Thank you for contacting Apple Developer Technical Support (DTS). Our engineers reviewed your request and came to the conclusion that there is no supported way to achieve the desired functionality, given the current configuration of the delivery system.


Hello,

Technical support for developers is not able to format other developer software on your behalf. Applications that do seemingly impossible things usually fall into one of two categories:

  • they break the rules and App Review hasn’t caught them yet (A)

  • their marketing material is economical with truth (B)

I can say that there is no supported way to lock the device from your iOS application.


Hope this helps someone in the future.

+4
source

After a long study, I found it impossible to lock the screen programmatically. But I found two ways to think there: 1. Hack an iOS device; 2. Use the MDM technique to achieve this. But it will be a huge job. We need to create a server to communicate with iOS devices.

0
source

All Articles