Created
March 3, 2015 02:43
-
-
Save jchernan/79ec9b36dd683dcbf3b1 to your computer and use it in GitHub Desktop.
Sample usage of AVAudioSessionInterruptionNotification v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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