Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jchernan/79ec9b36dd683dcbf3b1 to your computer and use it in GitHub Desktop.
Save jchernan/79ec9b36dd683dcbf3b1 to your computer and use it in GitHub Desktop.
Sample usage of AVAudioSessionInterruptionNotification v2
func addInterruptionNotification() {
// add audio session interruption notification
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "handleInterruption:",
name: AVAudioSessionInterruptionNotification,
object: nil)
}
func handleInterruption(notification: NSNotification) {
if notification.name != AVAudioSessionInterruptionNotification
|| notification.userInfo == nil{
return
}
var info = notification.userInfo!
let value = (info[AVAudioSessionInterruptionTypeKey] as NSNumber).unsignedLongValue
if let type = AVAudioSessionInterruptionType.fromRaw(value) {
switch type {
case .Began:
// interruption began
println("began")
case .Ended:
// interruption ended
println("ended")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment