gpt4 book ai didi

iPhone : User option to keep the app awake

转载 作者:行者123 更新时间:2023-12-03 19:41:52 27 4
gpt4 key购买 nike

我有一个倒计时器,它通过 AVAudioPlayer 每秒都会发出“蜂鸣声”。我想设置一个用户选项以通过开/关开关保持应用程序唤醒。我知道为了使应用程序保持唤醒状态,您需要设置[UIApplication共享应用程序].idleTimerDisabled = YES;但是我如何通过开关控制"is"或“否”选项?另外,我注意到,在使应用程序保持唤醒状态超过 5 分钟后,音频(在我的情况下为嘟嘟声)被静音?这是为什么?我怎样才能避免它?

最佳答案

你需要一个 UISwitch。只需将以下方法连接到您的 .m:

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

当然,您需要首先设置正确的值:

mySwitch.on = [UIApplication sharedApplication].idleTimerDisabled;

为了完成,您必须将以下行添加到 .h 中并将它们连接到 .nib 文件中:

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

- (void) switchChanged:(id)sender;

关于iPhone : User option to keep the app awake,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7743589/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com