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:
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.
Go to Settings > Personalization > Lock screen. Under Background, select Picture or Slideshow to use your own picture(s) as the background for your lock screen.
In Windows 10: Click the Start menu, then Control Panel (gear icon). Click Personalization, then Lock Screen. Optionally, choose a Background option from the dropdown list.
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.
After contacting Apple Developer Technical Support there is no supported way to achieve this functionality without using private API's. Use of these will cause for your app to be rejected.
My guess is that CellControl was able to make it through review because the only way that they make use of this feature is if you have their hardware installed in your vehicle, device paired with it, and begin driving. My guess is that during app review, Apple did not buy one of their devices and actually test it. Although I've always been under the impression that they scan you binaries to check for undocumented API use but that seems to be wrong.
The other possibility as @Chris mentioned is they could have had an arrangement with Apple before starting development. While 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 have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
Hello,
Developer Technical Support is not in a position to reverse engineer other developer's software on your behalf. Apps that are doing seemingly-impossible things generally fall into one of two categories:
they're breaking the rules and App Review hasn't caught them yet (A)
their marketing material is being economical with the truth (B)
I can say that there is no supported way lock the device from your iOS app.
Hope this helps someone in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With