未发送本机FCM iOS推送通知

时间:2020-01-01 14:54:34

标签: ios firebase react-native firebase-cloud-messaging apple-push-notifications

首先环境是React本机,我尝试按照rnfirebase包中的说明在iOS中设置推送通知,我该怎么做,我要在Real iPhone Device上进行测试

  1. 创建密钥

enter image description here

  1. 然后添加到firebase

enter image description here

  1. 添加Google-service.plist并从Firebase文档添加以下设置

enter image description here

并获得能力 enter image description here

  1. 然后我安装pod包

enter image description here

  1. 运行应用程序获得令牌

enter image description here

  1. 在云消息传递控制台上使用令牌发送

通知未发送,我不知道是什么错误,因为消息也是从FCM发送的,以及在APNS上发生的错误,我只是感到迷惑

感谢前进

,也可以尝试直接与按钮连接 enter image description here

,也没有再收到

然后尝试对Firebase使用具有相同证书的Onesignal,即使在测试消息上也可以使用

1 个答案:

答案 0 :(得分:1)

您在Pusher中使用的令牌看起来不正确。我的远程通知令牌看起来像这样。

enter image description here

我只是在测试静默推送,但是对于常规警报,令牌看起来很相似。这是我用来获取令牌的代码。我的猜测是您正在将错误的令牌推向FCM。

fileprivate func convertHexDataToString(_ data: Data) -> String {
    var string: String = ""
    for i in 0..<data.count {
        string += String(format: "%02.2hhx", data[i] as CVarArg)
    }
    return string
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let tokenString = convertHexDataToString(deviceToken)
    #if DEBUG
    print("APN sandbox token: '\(tokenString)'")
    Messaging.messaging().setAPNSToken(deviceToken, type: .sandbox)
    #else
    print("APN prod token: '\(tokenString)'")
    Messaging.messaging().setAPNSToken(deviceToken, type: .prod)
    #endif        
}