Users want Auto-Lock turned off while using my navigation utility. Is it possible to control Auto-Lock from an application?
[also, "How to stop your iPad from sleeping or suspending"]
This will prevent the screen to dim and go to sleep.
[UIApplication sharedApplication].idleTimerDisabled = YES;
Related
Is there any Swift command to actually set the Auto-Lock to Never or a specific time period? I want to create a simple app that only has two buttons: one is to set the Auto-Lock to Never and the other one is to set it back to iOS default (1 min).
So when a user open this app and tap the Never button, s/he can open other apps but the iPhone or iPad will never auto lock while running the other apps. If s/he is done with other apps, s/he can open this app again and tap the Default button to set the Auto-Lock back to 1 min.
I understand this can be done from the Settings but I am just curious how I can do it from the backend using Swift.
I am new to Swift, btw.
Thanks much!
So when a user open this app and tap the Never button, s/he can open other apps but the iPhone or iPad will never auto lock while running the other apps
You can't do that. You are sandboxed. You cannot affect what happens to the user while running some other app.
When app is open, try to disable the idleTimer in viewDidLoad
UIApplication.shared.isIdleTimerDisabled = true
When app is closed to open other apps, try to -enable again idleTimer when yourViewController disappears, so put this in viewDidDisappear
UIApplication.shared.isIdleTimerDisabled = true
You need to make use of this API call to set the idle timer disable and enable.
This is in objective-C. Just convert it to swift. The API is available in UIApplication.h
-(void) onApplicationDidActivate:(NSNotification*) notification
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
-(void) onApplicationWillDeactivate
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
I want to lock the device home screen programatically from my app. Is it possible in IOS?
In my app, if the user is idle for 1 minute, i want to lock the device. This is the scenario.
Thanks
Jithen
you can lock the phone using bellow code
[UIApplication sharedApplication].idleTimerDisabled = YES;
You can lock your own App by Adding a block view on Appdelegate's window. But locking your device is the responsibility of OS. I think if you somehow implement this then still aplle might reject your app on it.
So, I was looking for a way to keep the user's iPhone display on for a clock app. I found [UIApplication sharedApplication].idleTimerDisabled = YES; but that keeps the device from locking all of the time. I tried to [UIApplication sharedApplication].idleTimerDisabled = NO; when the application goes into the background, but that doesn't work. How can I safely keep the user's device from sleeping while my app is running?
Alter the idleTimerDisabled property whenever your app changes its active state - if you're going to be backgrounded, re-enable the timer, and when you regain control, disable the timer again.
Here's my solution, using XCode 6.2.
iPhone - phone goes to sleep even if idleTimerDisabled is YES
Basically, even now, in 2015, the only way to safely make sure that the device doesn't go to sleep is to repeatedly call a piece of code to keep the device awake.
-(void)callEveryTwentySeconds
{
// DON'T let the device go to sleep during our sync
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}
How could I make sure that iPhone doesn't disable the screen or go to sleep for about 20 to 30 minutes?
Check this link: Keep iphone active while running program
In short:
[UIApplication sharedApplication].idleTimerDisabled = YES;
how to set iPhone device to stay active ( to not lock ) while my app is running ?
Any idea
I'm not sure if this prevents the device from locking, but you can prevent the screen from dimming with the UIApplication's idleTimerDisabled property:
[UIApplication sharedApplication].idleTimerDisabled = YES;
From the documentation:
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.
This code will prevent your iPhone from going to sleep while your app is running
// avoid sleeping when this application is running
UIApplication *application = [UIApplication sharedApplication];
application.idleTimerDisabled = YES;
// Or simpler
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
If you landed here looking for an answer in Swift, it's this:
UIApplication.sharedApplication().idleTimerDisabled = true
for Swift 3
UIApplication.shared.isIdleTimerDisabled = true
The warning in this comment still applies.