我正在创建一个计时器应用程序,我试图让它在计时器结束时(秒数达到0),系统声音将一直播放,直到用户点击设备上的按钮。
我对此按钮的偏好可以是屏幕上的任何位置以及家庭/音量/铃声按钮e.t.c,类似于当您接到电话时静音手机铃声。
我目前为UIAlertController设置了此代码
let timerFinished = UIAlertController(title: "Timer Up", message: nil, preferredStyle: UIAlertControllerStyle.alert)
timerFinished.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action: UIAlertAction!) in
}))
present(timerFinished, animated: true, completion: nil)
timerFinished.view.superview?.isUserInteractionEnabled = true timerFinished.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.alertClose)))
和
@objc func alertClose(gesture: UITapGestureRecognizer) {
self.dismiss(animated: true, completion: nil)
}.
所以从本质上讲,我的问题是:
1)是否可以使用物理按钮来执行禁用系统声音的操作? - 如果是这样的话?
2)一旦动作运行,你会如何设置禁用系统声音的东西? - 你会设置一个类似于:
的while循环while playSystemSound == true {
AudioServicesPlaySystemSound(SystemSoundID(THIS IS WHERE ID WOULD GO))
}
并运行以下代码:
playSystemSound = false
在alertClose(),OK按钮和物理设备按钮(如果可能)的操作中。
答案 0 :(得分:0)
尽管这不是一个答案,但现在却无法做到这一点。正如this问题/答案中所提到的,它违反了Apple的指导方针,即使用硬件按钮进行额外行为,但具有讽刺意味,因为相机应用程序本身使用音量按钮进行快门操作。