Disable automatic screen lock in iOS 5.1

拜拜、爱过 提交于 2019-12-02 20:05:02

Just setting [UIApplication sharedApplication].idleTimerDisabled = YES; in

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

works well for me. However, there is a caveat. I have noticed that every time I invoke camera utility to take a snapshot, idleTimerDisable gets set to NO behind the scene. So right after I upload my image, I had to call the following line of code again:

[UIApplication sharedApplication].idleTimerDisabled = YES;

I would not be surprised if there are more places throughout that require same strategy. So far this approach has worked without issues for me.

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

worked for me on iOS 5.1

No there should be no difference. Perhaps you have another mistake..
See iOS 5.0 to 5.1 API Diffs

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.

Maybe You exceeds the allowable time limit of being awake?

i know its is old, but i found this good and in Swift you can do it look a like this

application.idleTimerDisabled = true

Thanks for you answers! i use right now xcode 7 Beta 3 ( Swift 2 )

Works fine if your application is registered for some background task, for example GPS location updating.

For Swift, I use this to do outside of delegate:

    UIApplication.sharedApplication().idleTimerDisabled = true
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!