Muhammad Zubair Ghori
Muhammad Zubair Ghori

Reputation: 713

How to fix Failed to fetch default token error?

enter image description here

I am getting this error after installing in iphone.

Upvotes: 36

Views: 36544

Answers (9)

Guru Prasad mohapatra
Guru Prasad mohapatra

Reputation: 1969

Go to Signing & Capabilities And Add Push Notification Capability

Upvotes: 1

Jiang Wang
Jiang Wang

Reputation: 325

Well, I also got this same problem. Can't fix it using solutions introduced by other posts. It seems that the communication between your client App FCM SDK and the FCM server goes wrong.

My fix was I loginned to my VPN (mainland China can't use google service if you don't do this). Then I could get the firebase token.

Besides, if you failed to get the token. Next time you try to access the firebase token using [[FIRInstanceID instanceID] token]. Firebase SDK will try to fetch the token again if it's still nil, and if this attempt succeeds, the token refresh notification (kFIRInstanceIDTokenRefreshNotification) will be posted.

Upvotes: 1

HiteshGs
HiteshGs

Reputation: 587

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.

Upvotes: 4

eussam
eussam

Reputation: 93

Have been stuck for a while with this, for me the reason why I could not make it work was that I was using a secondary firebase app. It looks like a bug to me. As a workaround, I had to initialize the additional app before the default app (in AppDelegate.m):

//initialise the secondary app, for example:
NSString *logFirebaseOptionFile = [[NSBundle mainBundle] pathForResource:@"GoogleService-LOG-Info" ofType:@"plist"];
FIROptions *firebaseOptions = [[FIROptions alloc] initWithContentsOfFile:logFirebaseOptionFile];
NSString *logAppName = @"mybands_logs";
[FIRApp configureWithName:logAppName options:firebaseOptions];

//then the default app for FCM to work
[FIRApp configure];

Upvotes: 1

Leap Bun
Leap Bun

Reputation: 2295

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

Upvotes: 1

Rachit Rawat
Rachit Rawat

Reputation: 2639

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.

Upvotes: 27

Phil
Phil

Reputation: 4870

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

Upvotes: 11

yoziru_desu
yoziru_desu

Reputation: 289

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

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

Upvotes: 28

starlord_amj
starlord_amj

Reputation: 255

You have to fix this line before handling this error:

Failed to fetch default token Error Domain=com.firebase.iid Code=0 "(null)"

Here is an answer to fix this issue

Upvotes: 0

Related Questions