开发者

iPhone : User option to keep the app awake

I have a count down timer that "beeps" every second it counts through AVAudioPlayer. i want to set a user option to keep the app awake through an on/off switch. i know that in order to keep the app awake you need to set [UIApplication sharedApplication].idleTimerDisabled = YES; however how would i control the YES or NO option through a switch? Also, i noticed that after keeping the app awake for more than 5 minutes the开发者_如何学JAVA audio (a beep sound in my case) is muted? Why is that and how can i avoid it?


You need a UISwitch. Just connect it to the following method to your .m:

- (void) switchChanged:(id)sender {
    UISwitch* switch = sender;
    [UIApplication sharedApplication].idleTimerDisabled = switch.on;
}

Of course, you need to set the correct value initially:

mySwitch.on = [UIApplication sharedApplication].idleTimerDisabled;

And just for completion, you have to add the following lines to your .h and connect them in you .nib file:

@interface YourClass{
    ...
    IBOutlet UISwitch* mySwitch;
}

- (void) switchChanged:(id)sender;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜