ios - Swift - How can I send a notification when AVPlayer gets overridden in the background mode? -
my app continues play music when app in background , hoping send user notification when avplayer
gets overridden (e.g. if user uses app on rides it).
currently solution use checkintimer
sets notification
, if app not checkin after x amount of time, notification
goes off, if checkin deletes notification , sets one. solution sucks..
any ideas?
you need observe audio interruptions:
import avfoundation func setup() { nsnotificationcenter.defaultcenter().addobserver(self, selector: #selector(myinterruptionhandler), name: avaudiosessioninterruptionnotification, object: nil) } func myinterruptionhandler(notification: nsnotification) { var info = notification.userinfo! var intvalue: uint = 0 (info[avaudiosessioninterruptiontypekey] as! nsvalue).getvalue(&intvalue) if let type = avaudiosessioninterruptiontype(rawvalue: intvalue) { switch type { case .began: // interruption began case .ended: // interruption ended } } }
Comments
Post a Comment