2

My application needs the screen be unlocked to do some functions, usually this app runs as background process, how can I prevent auto-lock? I mean on jailbroken environment.

Why does the code below can not be available from SpringBoard?

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Suge
  • 2,808
  • 3
  • 48
  • 79

2 Answers2

1

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

zbMax
  • 2,756
  • 3
  • 21
  • 42
  • I mean even when my app is changed to background. – Suge Jul 04 '13 at 09:59
  • yes, just add this line in your AppDelegate.m file in `application:didFinishLaunchingWithOptions` – zbMax Jul 04 '13 at 10:00
  • Sorry, after testing it doesn't works,... but maybe this can help you : http://stackoverflow.com/questions/12141634/how-can-we-allow-our-app-to-run-when-screen-is-locked – zbMax Jul 04 '13 at 10:08
1

Have a look on SpringBoard class

This code should be run in SpringBoard:

SpringBoard *sb = [UIApplication sharedApplication];
[sb clearIdleTimer];

After you get things done, remember to reset it to normal state:

[sb resetIdleTimerAndUndim:YES]; // or NO if you don't want the screen dims at once.
  • Why does this can not be available in SpringBoard? – Suge Aug 22 '13 at 10:24
  • This is not a public API and you have to add the header yourself. As for setIdleTimerDisabled, what I can only say is that SpringBoard is designed this way. –  Aug 22 '13 at 10:56
  • I have added the headers of SpringBoard to my project but no use. – Suge Aug 22 '13 at 13:32
  • This code has to be run in SpringBoard. If you call the method in other apps, it wont work –  Aug 22 '13 at 13:51
  • Yes, I call it in SpringBoard, I can't find out why doesn't work. – Suge Aug 22 '13 at 13:54