How to fix Failed to fetch default token error?

33,819

Solution 1

Using Xcode8, the fix was to simply enable Keychain Sharing in Capabilities

Open the app.xcworkspace file, select Target > Capabilities > Enable 'Keychain sharing'

Solution 2

Possible reasons for this issue:

  1. Device date was not set to the current date.
  2. Bundle ID is not same that one you set in GoogleService-Info.
  3. .p12 certificate uploaded on Firebase Console is not correct.

Solution 3

Make sure that:

  • Bundle ID is the same that one you set in GoogleService-Info
  • Code signing params (Target => Build Settings => Code signing) are corrects and match with p12 cert file you've set in Firebase. enter image description here

Also, you have to follow those tutos:

And don't forget to ask permission to user simply to add that in your app (In AppDelegate file, or in other ViewController for example):

let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()

Solution 4

i have same issue failed to fetch default token error domain=com.firebase.iid code=501 today spend 4 hours on this and finally got issue and thats my iphone time is wrong (manually i set diff time for testing)

so once check time when you have request firebase token.

Solution 5

Make sure you uploaded Development APNs certificate to Firebase. Go to Settings of your project => CLOUD MESSAGING tab.

Share:
33,819
Muhammad Zubair Ghori
Author by

Muhammad Zubair Ghori

Updated on June 13, 2021

Comments

  • Muhammad Zubair Ghori
    Muhammad Zubair Ghori about 3 years

    enter image description here

    I am getting this error after installing in iphone.

  • alizx
    alizx about 8 years
    it has still had the problem
  • Suke
    Suke over 7 years
    Could you clarify why we have enable this feature ? I did as above but it still not get FCM token.
  • Tim
    Tim over 7 years
    While it's always good to link back to another SO answer, please always include the full answer in the one you also provide the link. -1
  • Iulian Onofrei
    Iulian Onofrei over 7 years
    Best not to add that "in AppDelegate file for example", as no one will accept the push notifications permission on the first app start.
  • vbgd
    vbgd over 7 years
    "1. Device date was not set to the current date." a very important and interesting point. You saved me some time! Thanks! Anyhow, does anyone know why it doesn't work if the device date is not set to the current date?
  • Rachit Rawat
    Rachit Rawat over 7 years
    If the device date is not correct, then Firebase can't figure out when to fetch the device token next, as you know Firebase keep on trying to fetch tokens at a regular interval.
  • B 7
    B 7 over 7 years
    Why does this capability is required?
  • Krutarth Patel
    Krutarth Patel over 7 years
    @RachitRawat device date means.can you explain in detail?
  • Rachit Rawat
    Rachit Rawat over 7 years
    Device date means date on your iPhone. You can change it via Settings. @KrutarthPatel
  • Krutarth Patel
    Krutarth Patel over 7 years
    @RachitRawat thanks bro.i am getting red mark add push notification entiliment to app id.
  • Rachit Rawat
    Rachit Rawat over 7 years
    Anytime bro. Just upvote the answer instead of thanking me, since it took me years to figure out the solution for this issue. @KrutarthPatel
  • Krutarth Patel
    Krutarth Patel over 7 years
    @RachitRawat red mark error sometime come and go.can you guide?
  • Rachit Rawat
    Rachit Rawat over 7 years
    @KrutarthPatel Can you be more specific? What's the error line it's showing?
  • Tim
    Tim over 7 years
    This was a fix when you have no Entitlements file, because the APNS Capability alone wouldn't generate an Entitlements file, causing the app to not register with APNS. I believe this has since been fixed, but regardless, if you have a manual Entitlements file, or other capabilities that generate one, this will not change anything.
  • AaoIi
    AaoIi about 7 years
    You saved my day really !
  • quarezz
    quarezz about 7 years
    Thumbs up for Device date!
  • Ethan Humphries
    Ethan Humphries about 7 years
    P12 Certificate for me was for development rather than distribution, thanks.