iOS:注册令牌无效。检查令牌格式

时间:2016-12-27 10:37:28

标签: ios firebase firebase-cloud-messaging firebase-notifications

我是Firebase以及iOS的新手。我正在尝试使用FCM发送推送通知。

我在FCM上注册了一个iOS应用。添加了.p12个证书。根据FCM开发的代码。

通过Firebase Console发送通知时,我收到错误Invalid registration token. Check the token format.。我不知道我做了什么错误。

FCM Console

2 个答案:

答案 0 :(得分:9)

iOS端有两个令牌

  1. iOS生成的令牌,在方法// inject get instance of Http service. http.post(API_HOST + '/prods/page/' + pageId + '/' + activeFilter', { 'query': { method: 'GET', isArray: true, timeout: 20000 } } ).subscribe((result) => { // handle result })

  2. 中收到
  3. Firebase生成的令牌didRegisterForRemoteNotificationsWithDeviceToken(您可以在AppDelegate中打印)

  4. 您面临的问题是因为firebase控制台门户需要通过方式2接收的令牌,并且您正在使用通过方式1接收的令牌。

答案 1 :(得分:-1)

解决这个问题

我遵循了为iOS提供的 FCM 的完整教程。但在测试或实施时,我使用的是 APN服务器。 使用APN Server时,只需要 .pem 文件

作为参考,这是我的.py文件代码

import random
from apns import APNs, Frame, Payload

sound = "default"
badge = None
alert = "Message"
identifier = random.getrandbits(32)

apns_enhanced = APNs(use_sandbox=True, cert_file='vendor.pem', enhanced=True)
payload = Payload(alert=alert, sound=sound, badge = badge)
apns_enhanced.gateway_server.send_notification(token_hex_office, payload, identifier=identifier)
apns_enhanced.gateway_server.force_close()

我稍后会提供更具描述性的答案

由于