How to fix Failed to fetch default token error?
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:
- Device date was not set to the current date.
- Bundle ID is not same that one you set in GoogleService-Info.
- .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.
Also, you have to follow those tutos:
- Notification: https://firebase.google.com/docs/notifications/ios/console-audience
- Configuration: https://firebase.google.com/docs/ios/setup
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.
![Muhammad Zubair Ghori](https://i.stack.imgur.com/5JSMF.jpg?s=256&g=1)
Muhammad Zubair Ghori
Updated on June 13, 2021Comments
-
Muhammad Zubair Ghori about 3 years
I am getting this error after installing in iphone.
-
alizx about 8 yearsit has still had the problem
-
Suke over 7 yearsCould you clarify why we have enable this feature ? I did as above but it still not get FCM token.
-
Tim over 7 yearsWhile 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 over 7 yearsBest not to add that "in AppDelegate file for example", as no one will accept the push notifications permission on the first app start.
-
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 over 7 yearsIf 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 over 7 yearsWhy does this capability is required?
-
Krutarth Patel over 7 years@RachitRawat device date means.can you explain in detail?
-
Rachit Rawat over 7 yearsDevice date means date on your iPhone. You can change it via Settings. @KrutarthPatel
-
Krutarth Patel over 7 years@RachitRawat thanks bro.i am getting red mark add push notification entiliment to app id.
-
Rachit Rawat over 7 yearsAnytime 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 over 7 years@RachitRawat red mark error sometime come and go.can you guide?
-
Rachit Rawat over 7 years@KrutarthPatel Can you be more specific? What's the error line it's showing?
-
Tim over 7 yearsThis 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 about 7 yearsYou saved my day really !
-
quarezz about 7 yearsThumbs up for Device date!
-
Ethan Humphries about 7 yearsP12 Certificate for me was for development rather than distribution, thanks.