I have a button in a simple view with on click function :
@IBAction func watchAlert(sender: AnyObject) {
showAlert()
for i in 1...2{
AudioServicesPlaySystemSound (1005);
sleep(2)
}
}
func showAlert(){
var alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
alert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: dismissAlert ))
}
func dismissAlert(alertView: UIAlertAction!)
{
println("User click ok button")
}
Even though I am trying to call showAlert() before playing the audio, I could only see the alert getting displayed only after sound gets played. I want the alert to be present first and then sound should play. Any help is appreciated.