Firebase on iOS: Initialising FIRApp without GCMSenderID possible? - ios

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!

Related

iOS, Firebase - Firebase causing crash - How to unconfigure app so that I can use database?

I configured my app using
FirebaseApp.configure();
In my Appdelegate and launched the app.
I then needed to add database functionality so I removed the above code (because it crashes and tells me the app is already configured) and added:
AppDelegate.ref = Database.database().reference()
But then I get this error:
must call `[FIRApp configure]` (`FirebaseApp.configure()` in Swift) before using Firebase Database.'
So, I am now stuck because if I add the configure() back my app just crashes and the error tells me the app is already configured.
Do I have to reconfigure? If so, how do I go about doing that as there is nothing in the documentation on this?
As suggested by Francesco, I redownloaded the configuration file. This fixed the issue.

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.

How to fix Failed to fetch default token error?

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

App crash on using Fabric and TwitterKit

I've got this line of code on my application didFinishLaunchingWithOptions delegate method and it causes a crash saying:
'[Fabric] Value of Info.plist key "Fabric" must be a NSDictionary.'
Anyone can help me with this one?
Here's the code that causing the crash:
[[Twitter sharedInstance] startWithConsumerKey:#"consumer_key" consumerSecret:#"secret_key"];
[Fabric with:#[[Twitter sharedInstance]]];
Alex from Fabric here. To use different Twitter API keys or API keys generated on apps.twitter.com, you're declaring it correctly in your code above. It sounds like you may not have fully onboarded your app through the Fabric app, and required entries, like the Fabric APIKey, are missing from your info.plist.
Some more info on the Fabric Mac App and info.plist:
When you onboard an kit through the Mac App, a Fabric Dictionary entry is injected into your info.plist. Under the Fabric parent, there will be two children entries: APIKey and Kits.
Your Fabric API key, if it's not injected for some reason (it should be added automatically if you're using the Fabric app) or you want to manually change it, can be found by visiting https://fabric.io/settings/organizations, clicking your organization and clicking "API Key" below the organization title.
The Kits array contains an Item X for each Fabric kit you've included. If you've included Twitter Kit, the automatically provisioned consumerKey and consumerSecret are listed under KitInfo.
I followed the steps as described above but still was getting this error
uncaught exception 'TWTRInvalidInitializationException', reason:
'Attempted to call TwitterKit methods before calling the requisite
start methods; you must call +[Fabric with:#[Twitter class]] before
using the methods on TwitterKit
As i am using multiple kits i tried to initialize on different calls as follows
[Fabric with:#[[Crashlytics class]]];
[Fabric with:#[[Twitter class]]];
As per Fabric documentation for + (instancetype)with:(NSArray *)kitClasses;
Only the first call to this method is honored. Subsequent calls are
no-ops.
So only Crashlytics was initializing and Twitter got ignored.
Solution was to initialize as follows;
[Fabric with:#[[Crashlytics class], [Twitter class]]];

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.

Resources