我正在创建一个计时器应用程序,并且我正在尝试使其在计时器结束时(秒数达到 0),系统声音将继续播放,直到用户单击设备上的按钮。
我对这个按钮的偏好将是屏幕上的任何位置以及主页/音量/铃声按钮等,类似于您在接到电话时静音电话铃声。
我目前为 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 按钮和物理设备按钮的操作中(如果可能)。