【发布时间】:2018-06-07 07:29:33
【问题描述】:
我正在创建一个计时器应用程序,并且我正在尝试使它在计时器结束时(秒数达到 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 按钮和物理设备按钮的操作中(如果可能)。
【问题讨论】:
-
这不太可能是你想听到的,但我认为你不能:stackoverflow.com/questions/7643942/…
-
好的,谢谢 BHendricks 告诉我,因为它确实为我节省了很多时间,因为我知道这是不可能的。
标签: swift xcode audio system-sounds