在通过传入的背景视频通话打开应用程序时显示我的UI时,我有些困惑。当应用程序在后台运行时,我成功使iOS调用了默认的“传入视频通话”界面,但是在接听电话后,我的应用程序没有被正确唤醒吗?
当我收到呼叫推送时,我会设置一个CXProvider并将来电通知给CallKit:
func handleIncomingCallFromBackground() {
//These properties are parsed from the push payload before this method is triggered
guard let callingUser = callingUser, roomName != nil else {
print("Unexpected nil caller and roomname (background)")
return
}
let callHandleTitle = "\(callingUser.first_name) \(callingUser.surname)"
let configuration = CXProviderConfiguration.default
let callKitProvider = CXProvider(configuration: configuration)
callKitProvider.setDelegate(self, queue: nil)
let callHandle = CXHandle(type: .generic, value: callHandleTitle)
self.callHandle = callHandle
let callUpdate = CXCallUpdate.default
callUpdate.remoteHandle = callHandle
let callUUID = UUID()
self.callUUID = callUUID
callKitProvider.reportNewIncomingCall(with: callUUID, update: callUpdate) { error in
if error != nil {
self.resetTwilioObjects()
}
}
}
我响应CXProvider的应答呼叫委托方法,在该方法中,我从服务器获取视频呼叫的访问令牌,向服务器发送响应以提醒呼叫者我们已接受呼叫,然后执行到我们自己的视频通话控制器(这是 jobsVC.showVideoCallVC()所做的全部)的一个步骤,该控制器处理通过Twilio会议室等连接呼叫的过程。
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
guard let customer = callingUser, let callHandle = self.callHandle, let uuid = callUUID, let roomName = roomName else {
resetTwilioObjects()
return
}
self.twilioAPI = TwilioAPI()
self.twilioAPI!.accessToken(room: roomName) { (success, accessToken) in
switch success{
case true:
guard let token = accessToken else {
return
}
let customerID = customer.userID
DispatchQueue.global().asyncAfter(deadline: .now() , execute: {
self.twilioAPI!.postResponse(customerID: customerID, status: 1) { (success) in
if let success = success, !success {
self.resetTwilioObjects()
}
}
})
guard let jobsVC = P_ChildHomeJobsVC.instance else {
print("Jobs VC unexpectedly nil")
return
}
//All this method does is perform a segue, the parameters are stored for later.
jobsVC.showVideoCallVC(callingUser: customer, callHandle: callHandle, callKitProvider: provider, callUUID: uuid, twilioAccessToken: token, roomName: roomName)
action.fulfill()
default:
action.fail()
self.resetTwilioObjects()
}
}
}
根据设备是否被锁定,我会得到不同的行为:
根据我的日志,实际上是正确执行了segue,甚至触发了视频调用控制器的内部工作,但是在我收到 applicationWillResignActive:委托调用后不久,一切都停止了。
奇怪的是(或者可能不是),如果在应用程序仍处于前台的状态下锁定了设备,那么一切都会按预期进行:该应用程序已正确唤醒,并显示了更新的UI。我注意到我仍然收到 applicationWillResignActive:调用,但是之后立即得到 applicationDidBecomeActive:。
有人对我可能做错了什么建议或提示吗?