开发者

Keep iPhone from sleeping [duplicate]

开发者 https://www.devze.com 2023-02-15 09:16 出处:网络
This question already has answers here: 开发者_JAVA技巧 Keep iphone active while running program (3 answers)
This question already has answers here: 开发者_JAVA技巧 Keep iphone active while running program (3 answers) Closed 9 years ago.

How can I keep the iPhone from sleeping?


To stop your app from timing out and going to sleep you can use:

[UIApplication sharedApplication].idleTimerDisabled = YES;

This will, obviously, disable the idle timer and stop your iphone from automatically going into sleep mode.

Edit: As middaparka stated you should re-enable the idle timer when you no longer need to keep the phone awake (generally after that view has been removed) using:

[UIApplication sharedApplication].idleTimerDisabled = NO;

Cheers


You can disable the automatic locking via...

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

However, you should really only do this within as few sections of your app as possible, and then re-enable it via...

[[UIApplication sharedApplication] setIdleTimerDisabled:NO];

...in the relevant view controller's viewWillDisappear: or dealloc.

0

精彩评论

暂无评论...
验证码 换一张
取 消