I am making Trivia View with tvos where 4 Uilabels are added as subviews each dispatched after time on custom queue after LOGIN
function used for dispatch on queue is :
func delayWithSeconds(_ seconds: Double, completion: @escaping () -> ()) {
self.TriviaDispatchQueue?.asyncAfter(deadline: .now() + seconds, qos: .default, flags: DispatchWorkItemFlags.detached, execute: {
DispatchQueue.main.sync {
completion()
}
})
}
My Dispatch code is:
func showTrivia() {
self.TriviaDispatchQueue = DispatchQueue(label: "TriviaQueue")
self.delayWithSeconds(5, completion: {
self.fadeIn(forView: self.Answer0Lbl)
self.delayWithSeconds(2, completion: {
self.fadeIn(forView: self.Answer1Lbl)
self.delayWithSeconds(2, completion: {
self.fadeIn(forView: self.Answer2Lbl)
self.delayWithSeconds(2, completion: {
self.fadeIn(forView: self.Answer3Lbl)
})
})
})
})
}
So when user moves from Trivia view to Other View in TV from top menu, then Queue is suspended to stop trivia
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
onMainThread {
self.TriviaClass.TriviaDispatchQueue?.suspend()
}
}
After that when user returns back to Trivia View then Queue is resumed:
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
onMainThread {
self.TriviaClass.TriviaDispatchQueue?.resume()
}
}
Everything works fine on first login but after LOGOUT and again RE-LOGIN crashes the app:Thread 1 exc_bad_instruction (code=exc_i386_invop subcode=0x0)
TRIVIA CLASS is shared with variable
var TriviaDispatchQueue: DispatchQueue?