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.

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();
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:

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.