我正在制作一个voip应用程序,其中使用了Firebase通知使用户知道来电。 Firebase通知是从我们的服务器发出的,它们已将Firebase与它们集成在一起。对于当应用程序处于后台或终止状态时的来电通知,我使用了Push kit委托。现在,当我的应用程序处于后台或终止状态时,我会在Firebase委托中收到正常的推送通知。我想在Push Kit委托中获取此通知有效载荷,目前我没有得到。我怎么能得到呢?我已经为Push Kit以及在后台模式和voip服务上实现了所有必需的东西,但是它不起作用。谁能告诉我如何在Push Kit委托中获取Firebase通知?这是我的推包代码,
let mainQueue = DispatchQueue.main
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
NSLog("voip token: \(token)")
UserDefaults.standard.set(token, forKey: Key_Push_token)
UserDefaults.standard.synchronize()
}
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
//print out the VoIP token. We will use this to test the notification.
let token = credentials.token.map { String(format: "%02.2hhx", $0) }.joined()
NSLog("voip token: \(token)")
}
private func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
userInfo = payload.dictionaryPayload["aps"] as? [AnyHashable:Any]
print(userInfo!)
let payloadDict = payload.dictionaryPayload["aps"] as? Dictionary<String, String>
let message = payloadDict?["alert"]
print(message!)
//present a local notifcation to visually see when we are recieving a VoIP Notification
if UIApplication.shared.applicationState == UIApplicationState.background {
print("Background")
}
else {
}
NSLog("incoming voip notfication: \(payload.dictionaryPayload)")
}
private func pushRegistry(registry: PKPushRegistry!, didInvalidatePushTokenForType type: String!) {
NSLog("token invalidated")
}
}
这是我发送到服务器端以点击此令牌NSLog("voip token: \(token)")
的通知的令牌,但是我没有收到任何通知。