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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…