ios - UIBackgroundTask throws error `no background task exists` -
an avaudioplayer
stopped in background tasks when app transitions background:
func stop() { var backgroundtask: uibackgroundtaskidentifier = uibackgroundtaskinvalid backgroundtask = uiapplication.shared.beginbackgroundtask() { uiapplication.shared.endbackgroundtask(backgroundtask) backgroundtask = uibackgroundtaskinvalid } dispatchqueue.global(qos: .default).async { self.audioplayer?.pause() uiapplication.shared.endbackgroundtask(backgroundtask) backgroundtask = uibackgroundtaskinvalid // symbolic breakpoint stops here } }
the function above gets called view controller contains avaudioplayer
when uiapplicationdidenterbackground
notification posted.
still error @ line backgroundtask = uibackgroundtaskinvalid
:
// can't endbackgroundtask: no background task exists identifier 1f, or may have been ended. break in uiapplicationendbackgroundtaskerror() debug.`
when remove line no errors. looked through similar questions on did not help.
what causing error?
Comments
Post a Comment