【问题标题】:UIAlertController Managing system sounds in swiftUIAlertController 快速管理系统声音
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    • 2015-02-05
    • 2011-07-25
    相关资源
    最近更新 更多