iOS: Invalid registration token. Check the token format

左心房为你撑大大i 提交于 2020-01-23 06:13:58

问题


I am new for Firebase as well as for iOS. I am trying to send push notification using FCM.

I registered an iOS app on FCM. Both .p12 certificates added. Code developed according to FCM.

While sending notification through the Firebase Console, I'm getting the error Invalid registration token. Check the token format.. I don't what mistake I did.


回答1:


There are two tokens you get at iOS side

  1. Token generated by iOS which is received in method didRegisterForRemoteNotificationsWithDeviceToken

  2. Token generated by Firebase FIRInstanceID.instanceID().token() (this you can print in AppDelegate)

The issue you are facing is because firebase console portal requires token received by way 2 and you are using token received by way 1.




回答2:


To solve the this issue

I followed complete tutorial of FCM provided for iOS. But while testing or implementing I used APN Server. While using APN Server you need only .pem file

For reference this is my .py file code

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()

Thanks



来源:https://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!