I have some music in my app that plays under AVAudioSessionCategoryAmbient
. Right now my problem is that when a popup from Apple like "Sign in to iTunes Store" pops up it pauses my music, but does not resume it. Thankfully it takes care of my SKScene
... but not the music. Is there some way to have a callback for when the alert is dismissed?
The weird thing is that other UIAlertView
s that I have made don't do this to the app, so I really don't know what is up.
List of alerts that pause scene and music:
I had similar problems sometime ago (beginning of Swift 1.2). I solved my problem by observing paused status for SKScene. SKScene have view which is SKView type.
private var queueContext = 0
override func didMoveToView(view: SKView) {
super.didMoveToView(view)
self.view.addObserver(self,
forKeyPath: "paused",
options: .New,
context: &queueContext)
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if context == &queueContext {
if let paused = change?[NSKeyValueChangeNewKey] as? Bool {
// TODO: react on paused status changes
}
}
else {
super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context)
}
}