iOS设备未收到语音通知

时间:2019-03-26 08:27:23

标签: swift pushkit

我正在开发一个呼叫应用程序,为此,我正在使用voip通知和Pushkit在后台或终止状态下接收通知。我已经从Apple帐户创建了Voip证书,然后为此创建了p12文件,之后我从p12生成了pem文件并将其提供给服务器端。我还启用了来自应用程序功能的后台和远程通知。当我从邮递员那里打API时,它成功打了,但是我在设备上没有收到任何通知。我还在我的应用程序中实现了Push Kit Delegate。但是didReceiveIncomingPushWithPayload委托没有被调用。我想念的是什么,有人可以帮我吗?

这是voip通知的代码,

let mainQueue = DispatchQueue.main
    // Create a push registry object
    let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
    // Set the registry's delegate to self
    voipRegistry.delegate = self
    // Set the push type to VoIP
    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)")

    let tokens = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
    print("voip token: \(tokens)")

    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")
}
}

我还在线测试了pem文件,它是正确的文件。但是我没有收到通知

0 个答案:

没有答案