【发布时间】:2017-07-03 09:31:39
【问题描述】:
在收到CallKit 的电话后,我尝试在Timer 12 秒后添加超时,但当应用程序处于后台时,它不会在Appdelegate 中触发。我的代码:
self.callBackgroundHandlerIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {
UIApplication.shared.endBackgroundTask(self.callBackgroundHandlerIdentifier!)
self.callBackgroundHandlerIdentifier = UIBackgroundTaskInvalid
})
DispatchQueue.global(qos: .userInitiated).async {
AppDelegate.callAnswerTimer = Timer.scheduledTimer(timeInterval: 12, target: self, selector: #selector(AppDelegate.hangUpOnCallTimeOut), userInfo: nil, repeats: false)
self.callBackgroundHandlerIdentifier = UIBackgroundTaskInvalid
}
func hangUpOnCallTimeOut(){
AppDelegate.timeOutTimer?.invalidate()
AppDelegate.timeOutTimer = nil
if #available(iOS 10.0, *) {
ProviderDelegate.sharedInstance.endCall(uuids: ApplicationDelegate.activeCalls!) { (uuid) in }
}
if self.callBackgroundHandlerIdentifier != UIBackgroundTaskInvalid {
UIApplication.shared.endBackgroundTask(self.callBackgroundHandlerIdentifier!)
}
}
任何想法我做错了什么?
【问题讨论】:
-
嗨哥们,你能分享一下关于通话超时的完整代码