7

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.

FCM Console

CinCout
  • 9,486
  • 12
  • 49
  • 67

2 Answers2

10

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.

Aditya Deshmane
  • 4,676
  • 2
  • 29
  • 35
  • could you please read my question? I am trying to fix this error for days. Many thanks https://stackoverflow.com/questions/50359010 – bibscy May 15 '18 at 20:59
  • 2
    FIRInstanceID.instanceID().token() has now changed to InstanceID.instanceID().token() – Droid Chris May 30 '18 at 20:54
  • I am facing this issue when I create a release build debug build is fine for me even I have uploaded the p12 certificate for both prod and dev environment ? Can you help – Abhishek Apr 29 '19 at 06:05
-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