2

我正在创建一个计时器应用程序,并且我正在尝试使其在计时器结束时(秒数达到 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 按钮和物理设备按钮的操作中(如果可能)。

4

1 回答 1

0

尽管这不是一个答案,但现在不可能做到这一点。如问题/答案中所述,使用硬件按钮进行额外行为违反了 Apple 的指导方针,但具有讽刺意味的是,因为相机应用程序本身使用音量按钮进行快门。

于 2017-12-27T14:44:31.593 回答