Fabric Crashlytics api key is null despite startWithApiKey - ios

On my iOS project, I updated Crashlytics from the version 2.x to the version 3.1.0.
I added a script in the Build Phases on xCode:
if [ ${MY_VAR} == 1 ]; then
./Pods/Fabric/Fabric.framework/run <api key> <build secret>
else
./Pods/Fabric/Fabric.framework/run <another api key> <another build secret>
Then, in my AppDelegate I added CrashlyticsKit to Fabric:
#if MY_VAR
[Crashlytics startWithAPIKey:#"api_key"];
#else
[Crashlytics startWithAPIKey:#"another_api_key"];
#endif
[Fabric with:#[CrashlyticsKit]];
NSLog(#"Crashlytics api key: %#", CrashlyticsKit.apiKey);
I tried to print the apiKey to be sure that everything work well, but unfortunately, the apiKey attribute is null.
Any suggestion?

Alex from Fabric here. We looked into this because there are a couple of strange things going on here! First off, the code in your AppDelegate should work, but you don't need both:
[Crashlytics startWithAPIKey...];
and
[Fabric with...];
You can remove one of them. [Crashlytics startWithAPIKey] is considered legacy but it will still to work.
It looks like you discovered a bug in our Crashlytics header file. In our header the property is apiKey but in the code it's APIKey. You can access the value by calling CrashlyticsKit.APIKey if you want to confirm that your logic is working, but we're going to fix this so that it's CrashlyticsKit.apiKey.
Are you using the official CocoaPod that we released?

Related

What happens under the hood when Fabric initializes it's modules (Crashlytics / Twitter)?

I want to integrate Crashlytics (3.9.3) into an internal library but I am faced with the following situation:
One of our internal libraries we are using is already using TwitterKit(2.2.0) with Fabric (1.6.7). This means that it is already doing it's initialization using this method:
[Fabric with:#[[Twitter class]]]
Now, this means that we can't initialize Crashlytics the same way because Twitter initialization would not be taken into consideration, since "Fabric with" method is going to be ignored on subsequent calls.
I know that the best method would be to call fabric in the main app like this:
[Fabric with:#[[Twitter class], [Crashlytics class]]];
but in our case it's desired to not impact the applications that are already using the the old lib, and keep compatibility.
Now, would it be safe to replace the current Fabric Twitter initialization and add the Crashlytics initialization with legacy method like this?
// replace original with this with info taken from Info.plist
[[Twitter sharedInstance] startWithConsumerKey:consumerKey
consumerSecret:consumerSecret];
// in another place
[Crashlytics startWithAPIKey:#"a1b2c3..."];
Is fabric doing any other stuff under the hood except the above or is it just parsing the info.plist for the keys and initializing the frameworks? Should we worry about any issues? Tested it and seems to be working ok.
Also, I am aware that Twitter is no longer part of the newest Fabric, but we are using some older versions here.
What I've also noticed is that if we keep the "Fabric with Twitter" part unchanged and initialize Crashlytics with "startWithAPIKey" method, Twitter will not be initialized ok.
Mike from Fabric here. Your approach may work, but could cause many issues as we haven't tested any of the most recent versions of Fabric with that version of Twitter so you would be at risk of seeing strange SDK behavior.

Initialize Fabric-Answeres in iOS with cocoa pods

I posted a post which was named "Initialize Fabric in iOS with cocoa pods", regarding initialization with crashlytics. It basically asked how to initialzie crashlytics with an API key, without having to go through info plist.
That was solved by doing this:
Crashlytics.start(withAPIKey: FABRIC_API_KEY)
But then im trying to do the same for Answers:
Answers.start(withAPIKey: FABRIC_API_KEY)
But Answers doesnt have any .start method? How can I initialize this then?
It is later used in this line:
Fabric.with([Crashlytics.self, Answers.self])
Mike from Fabric here. Answers is included within Crashlytics by default, you only need to init Answers separately if you're not using Crashlytics. Using:
Fabric.with([Crashlytics.self])
is all you need to do.

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

Error configuring Google analytics for iOS app with GoogleService-Info.plist

I followed this Google developer guide to add Google analytics to an iOS app using Cocoa Pods. I added the GoogleService-Info.plist and put the initialisation code in didFinishLaunchingWithOptions. The app builds fine, but then crashes at the point it tries to initialise GA. Specifically these lines of code:
NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, #"Error configuring Google services: %#", configureError);
The assert statement is failing and the output in the console is:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Error configuring Google services:
Error Domain=com.google.greenhouse Code=-200 "Unable to configure GGL."
{NSLocalizedFailureReason=Unable to parse supplied GoogleService-Info.plist. See log for details.,
NSLocalizedRecoverySuggestion=Check formatting and location of GoogleService-Info.plist.,
NSLocalizedDescription=Unable to configure GGL.}'
I can see this is due to the GoogleService-Info.plist file and after some investigation I found that even if I delete GoogleService-Info.plist I get the error, which leads me to believe that I had not added the file to the project correctly.
Here is a screenshot of what I checked when adding the file:
So I have made sure that it is added to all targets and that the file is in the root directory of the project, alongside the xcodeproj and xcworkspace files, as per the instructions on the Google developer guide.
I should also mention that this is a SpriteBuilder project, but I don't think that has anything to do with this. Also this was the first Cocoa Pod that I added, but all seems fine with that as the project builds and can find all the Google headers it needs.
I was also stuck with this strange piece of code. But you don't need it! Just remove configureWithError and all these things.
All you need is:
[[GAI sharedInstance] trackerWithTrackingId:#"UA-11111111-2"];
[GAI sharedInstance].trackUncaughtExceptions = YES;
Somewhere inside didFinishLaunchingWithOptions. (It's from the previous GA version, right?) So, that's it! Then, do anything you want in your app:
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:#"start screen"];
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];
My Podfile looks like this:
source 'https://github.com/CocoaPods/Specs.git'
pod 'Google/Analytics', '~> 1.0.0'
It works!
If you already integrate google signIn it provide plist for accessing the login service detail of your app. It means when you try to integrate the analytic you dont need to add the new GoogleService-Info.plist. You just add the following keys which are missing in the existing plist file.

Unable to find "GoogleService-Info.plist" while trying to integrate Google Sign-in in my app

I have followed : Integrating Google Sign-In into your iOS app
However when I execute the app, it halts in the app delegate itself - even before I can see my first view controller.
The reason is because of these few lines of code I wrote in the "application didFinishLaunchingWithOptions withOptions", which are:
"NSError* configureError;
[[GGLContext sharedInstance] configureWithError: &configureError];
NSAssert(!configureError, #"Error configuring Google services: %#", configureError);
[GIDSignIn sharedInstance].delegate = self;"
In the debug, when it reaches this code, it says
"Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Error configuring Google
services: Error Domain=com.google.greenhouse Code=-200 "Unable to
configure GGL." UserInfo=0x7ff9c2e1d000
{NSLocalizedRecoverySuggestion=Check formatting and location of
GoogleService-Info.plist., NSLocalizedDescription=Unable to configure
GGL., NSLocalizedFailureReason=Unable to parse supplied
GoogleService-Info.plist. See log for details.}'".
I put the GoogleService-Info.plist in my directory, but it still isn't working.
You must drag and drop the GoogleService-Info.plist file into your project in a location such as Shared Resources. When you have successfully added the file, you should also make sure to include it in the project build:
Double-check that in the "Build Phases" section of your project that your project is including GoogleService-Info.plist.
Double check the file name. The file name must be exactly GoogleService-Info.plist common misspellings include GoogleServices-Info.plist and GoogleService-info.plist - case sensitive and exactly named only will work.
I faced the same problem. And, actually, I solved it when in cocoapods file I placed "pod 'Google/SignIn'" instead of "pod Google". Hope it could help you too.
If you wanna get only GCM_SENDER_ID, try this workaround:
NSError* configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSString * gcmSenderID = [GGLContext sharedInstance].gcmSenderID;
NSLog(#"%#", gcmSenderID);
This happens to me when I updated the google pods. They changed the way they configure URL schemes. The best way is to just reconfigure the google signin.
For me..
I forgot to add the below pods. (cause i had some local issue before... so i removed all)
pod 'FirebaseUI/Auth'
pod 'FirebaseUI/Google'
pod 'FirebaseUI/Facebook'
pod 'FirebaseUI/OAuth' # Used for Sign in with Apple, Twitter, etc
pod 'FirebaseUI/Phone'
https://firebase.google.com/docs/auth/ios/firebaseui

Resources