iPhone : User option to keep the app awake

标签 iphone xcode sleep

我有一个倒计时器,它通过 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/

相关文章:

iphone - 将 NSManagedObject 子类转换为协议(protocol)

Xcode Guard Malloc 和设备调试 : 'libgmalloc.dylib' image not found

java - 当线程中断时继续 hibernate 剩余时间

android - Android地理围栏系统(Google Play服务)可以在手机休眠时触发事件吗

iphone - iPhone滑盖 View Controller 可用于音频播放器控件吗?

ios - AVCaptureVideoPreviewLayer 正确显示,但在 iPhone6 上除外

iphone - iOS 4 中的实时相机数据访问

ios - 如何在 build.json 中指定 Cordova 构建目标

ios - UIbutton点击问题-Swift

c - 在同一行中打印并在 C 中暂停