2

I am creating a timer app, and I am trying to make it so that when the timer ends (seconds reaches 0), a system sound will keep playing until the user clicks a button on the device.

My preference for this button would be anywhere on the screen and the home/volume/ringer buttons e.t.c, similar to if you were silencing a phone ringtone when you get a call.

I currently have this code set up for a 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)))

and

@objc func alertClose(gesture: UITapGestureRecognizer) {
    self.dismiss(animated: true, completion: nil)
}.

So in essence, my questions are:

1) Is it possible to use physical buttons to run the actions of disabling the system sounds? - if so how?

2) How would you setup something to disable system sounds once an action is run? - would you set up a while loop that says something like:

while playSystemSound == true {

    AudioServicesPlaySystemSound(SystemSoundID(THIS IS WHERE ID WOULD GO))

}

and run the code of:

playSystemSound = false

in the actions for the alertClose(), OK button and physical device buttons (if possible).

Akshay
  • 153
  • 3
  • 13
D-A UK
  • 1,084
  • 2
  • 11
  • 24
  • This is unlikely something you want to hear, but I don't think you can: https://stackoverflow.com/questions/7643942/is-it-possible-to-use-iphones-volume-control-buttons-for-some-other-purpose – BHendricks Dec 27 '17 at 00:16
  • 1
    Ok well thank you BHendricks for telling me because it does save me a lot of time knowing that it is impossible. – D-A UK Dec 27 '17 at 08:08

1 Answers1

0

As much as this is not an answer, it's not possible to accomplish this right now. As mentioned in this question/answer, it's against Apple's guidelines to use hardware buttons for extra behavior, but ironic since the camera app itself uses the volume button for the shutter.

BHendricks
  • 4,423
  • 6
  • 32
  • 59