问题
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
Token generated by iOS which is received in method
didRegisterForRemoteNotificationsWithDeviceToken
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