How to fix Failed to fetch default token error? - ios

I am getting this error after installing in iphone.

Using Xcode8, the fix was to simply enable Keychain Sharing in Capabilities
Open the app.xcworkspace file, select Target > Capabilities > Enable 'Keychain sharing'

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.

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

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.

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

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];

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.

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

Go to Signing & Capabilities And Add Push Notification Capability

Related

Firebase on iOS: Initialising FIRApp without GCMSenderID possible?

I'm initialising FIRApp in my iOS App using the configureWithOptions api as follows:
FIROptions *options = [[FIROptions alloc] initWithGoogleAppID:#"x:xxxxxxx:ios:xxxxxxx" bundleID:nil GCMSenderID:#"xxxxxxxx" APIKey:nil clientID:nil trackingID:nil androidClientID:nil databaseURL:#"https://xxxxxx.firebaseio.com" storageBucket:nil deepLinkURLScheme:nil];
[FIRApp configureWithOptions:options];
This is being done in order to dynamically instantiate it with minimal required parameters obtained through the app's server without having the Firebase plist file added to the app's Xcode project. However, if I omit GCMSenderID by setting it as nil, the app gives an exception when running it. Why is the GCMSenderID required in the code above & is there any way to work without it? Kindly let me know. Thanks in advance!

Firebase iOS setup - nil senderID

When trying to setup Firebase for iOS, I get this error in the console:
<FIRInstanceID/WARNING> Firebase messaging not setup correctly, nil senderID.
Looks like Firebase doesn't detect well my GoogleService-Info.plist, I tried putting it a few locations (root included) but it didn't work. Any idea/pointer on how to fix that ?
The solution was simple, I just forgot to put [FIRApp configure]; in AppDelegate.m
EDIT: And if your get this error, it means you forgot to add GoogleService-Info.plist to all the targets (as described by the other answer):
<FIRInstanceID/WARNING> Failed to fetch APNS token Error Domain=com.firebase.iid Code=1001 "(null)"
Ensure that the file GoogleService-Info.plist is included with all the targets for which your app builds code that uses Firebase.

GCM : Configuring subspecs failed # CloudMessaging

I am trying to integrate Google Cloud Messaging in my iOS application. I have followed every instruction provided in this link.
I have also integrated Google sign-in and it works fine.
The problem is I am getting assertion failure in the below code.
NSError* configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, #"Error configuring Google services: %#", configureError);
Which is used to configure subspecs for cloud messaging.
This code above is in didFinishLaunchingWithOptions method in AppDelegate.m file.
The error generated is:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error configuring Google services: Error Domain=com.google.greenhouse Code=-104 "Unable to correctly configure subspec CloudMessaging" UserInfo={NSLocalizedDescription=Unable to correctly configure subspec CloudMessaging, NSLocalizedFailureReason=GCM Sender ID must not be nil or empty.
Now I don't understand the meaning of this error. Yes, it clearly states that sender ID must not be nil. But from where it gets null ID.
I have tested this in simulator. I don't know if that affects or not.
If I comment this code and run in real device I also get the registration token but I don't receive any notification from my server. Server side code is tested and works fine for android.
Finally I solved the problem. First of all thank you all for quick reply.
What I did is explained in the following steps.
Get GCMExample project. Which I downloaded from Github because pod try google does not list GCMExample project.
Generate GoogleServices-Info.plist file from here
Compare plist files of GCMExample and MyProject.
Here I got the difference in it. In My project GCM was disabled and there was no Sender ID in it. I don't know how the hell did that happened.
So I manually set the GCM service enabled and added sender ID of my app that I previously created.
That is how I solved my problem.
Check Below Link for certificate
cloud-messaging_ios_certs
Make sure you are following below steps correctly
Create your App ID with Push Notifications ON.
Create your SSL Certificate.
Download and run it in order to be added to the Provisioning Profile.
To make sure that your provisioning profile has this certificate go to Xcode -> Preferences -> Account -> Your Apple ID -> Your Team -> View Details -> Download All.

App is crashing while using Google Sign in for iOS with AssertionFailure

I tried to implement Google Sign in for iOS according to the docs - iOS implentation. But the app is crashing with an error while calling
[[GGLContext sharedInstance] configureWithError: &configureError];
in my App Delegate's application:didFinishLaunchingWithOptions method.
Error :-
Assertion failure in void validateGoogleSignInWithURLSchemes(NSArray *__strong)(), googlemac/iPhone/Greenhouse/Source/GGLURLSchemeUtil.m:39
I have added GoogleService-Info.plist to the target resources and also added URL Types for REVERSED_CLIENT_ID and Bundle Identifier as explained in the docs and also referenced here.
Is there something I am missing or what should I do to fix the same?
It was due to a simple spelling mistake. I had my Bundle Identifier wrong in the URL scheme while adding URL Types.
Please suggest if it's better to delete this question. I will delete the same.

I can't get HealthKit to work. Missing Entitlement

I am having a hard time to get HealthKit working for my iOS App. I have done all the steps I have found so far and none seem to solve my problem I keep getting this error when trying to authorize Healthkit:
Error Domain=com.apple.healthkit Code=4 "Missing com.apple.developer.healthkit entitlement." UserInfo=0x78fa24e0 {NSLocalizedDescription=Missing com.apple.developer.healthkit entitlement.}
Here is my code asking for authorization:
if([HKHealthStore isHealthDataAvailable]) {
self.healthStore = [[HKHealthStore alloc] init];
[self.healthStore requestAuthorizationToShareTypes:nil readTypes:[self dataTypesToRead] completion:^(BOOL success, NSError *error) {
if (!success) {
NSLog(#"HK Error: %#", error);
[self presentHealthAlert:#"You didn't allow APP to access HealthKit Data. Please go to Settings and set up APP permissions." withTitle:#"Error"];
} else {
[self presentHealthAlert:#"Thank You For Access" withTitle:#"Success"];
}
}];
} else {
[self presentHealthAlert:#"Health Data Not Available" withTitle:#"Success"];
}
And Yes, I have enabled it on my project Capabilites, and yes I have enabled it in my Dev Center App ID. Is there anything else I might be missing?
I had this problem with a watchOS 2 app. The resolution was to ensure I had enabled the HealthKit entitlement for both the iOS app and the watch extension.
I had wrongly assumed the switch for the iOS app would be inherited by the watch extension.
You have to make sure that you click on your program on the left side of Xcode (the top of your file hierarchy). You'll come to a general settings screen in the main window (to the right) where you will see your bundle identifier, deployment target, and additional settings. Click on the tab at the top that says Capabilities. Now you will see a toggleable list which includes HealthKit. You have to activate it here before you can use it in the app.
Edit: Here is an image from Xcode that might help you find this if you're not familiar with setting dependencies or other program specific settings.
It is in this list on the right, towards the bottom you'll see HealthKit. It will check several things once you toggle it on and verify that you can use it.
A bit old, but for anyone else who has issues, I had to manually refresh my provisioning profiles as well in XCode 6.2 (Preferences -> Accounts).
I ended up here after reaching my wit's end. Nothing worked and I clearly had the HealthKit entitlement enabled so finally I just restarted the phone. VoilĂ . Restarting cleared the missing entitlement errors.
Click on the Watch App Extension target.
Tap on the Capabilities.
Scroll down to the bottom and turn on the HealthKit.
I managed to get my entitlement working by ensuring that I had a device registered. Once I got my iPhone showing under the simulator and I didnt have any unresolved issues under the identity section of the app it all loaded ok.
You may find that although you have turned on the HealthKit entitlement on in xcode that there is a second entitlements file that does not contain the healthkit boolean. I found that while the obvious entitlements file (at the top level) had the correct information, a different entitlements file had been created under Resources that did not contain the healthkit entitlement. fixing that file fixed my problem.

Resources