Multiple firebase apps, crash reporting configuration issue - ios

I have configured multiple firebase databases in my single iOS app.
here is the code in my AppDelegate, that selects which firebase db I have to choose at run-time
func initFirebase(){
// Check the Flag which Firebase to connect with
if (UserDefaultsManager().getFirebaseConfiguration()){
let resource = UserDefaultsManager.env_firebase?.value(forKey: "resource") as! String
print("resource \(resource)")
let filePath = Bundle.main.path(forResource: resource, ofType:"plist")
let options = FirebaseOptions(contentsOfFile:filePath!)
FirebaseApp.configure(options: options!)
}
}
This is all working fine.
Issue is with crash reporting, I have to make the firebase crash reporting dynamic too.
Right now I have configured my firebase crash reporting with jBackend-genetech-dev-crash-reporting.json , here is my crash reporting shell script.
# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist (its my genetech-dev firebase service account actually) file
GOOGLE_APP_ID=1:740631780656:ios:ddccc74c2f726b3a
# Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "${SRCROOT}/JamesApp/jBackend-genetech-dev-crash-reporting.json"
So When I connect my app to the firebase db with configuration defined in service account GoogleService-Info.plist its working flawlessly i.e I am getting the crash reports with the exact line number of the crash. here is the screenshot.
But whenever I connect with other firebase accounts example GoogleService-Info-mh6-prod.plist, I am getting the crash reports in this case too but with no Line number, see screenshot below.
More Info
Am I testing on real device? Yes
Is bitcode support disabled in my project? Yes
Question:
How to make my crash reporting script dynamic in my case.
I have seen this iOS Firebase Crash Reporting - Error running build script , i.e making the script dynamic depending upon the app configuration variable i.e release/debug. but my scenario is different, my app select the firebase database depending on the app's System settings bundle. seen screenshot below.

Related

Will Firebase Analytics work from the simulator in Xcode?

In an IOS app I have
and I ensured the plist "defeat" entry is not there, and then I have analytics events like
Analytics.logEvent("touchedButton", parameters: nil)
In fact, if I run the app just in the Xcode simulator .. are these events reported to Firebase Analytics and show up?
Or perhaps if you build to an iPhone?
Or does it only work if it's an actual build which has gone through TestFlight?
Surprisingly I couldn't find this info anywhere.
Is it precisely here that such custom events will show:
Yes, both simulator or device will work.
If you haven't already read, read their getting started tutorials, it covers most of it https://firebase.google.com/docs/analytics/ios/start
A couple of points
Make sure when you configure your Firestore settings , you enable analytics
AnalyticsConfiguration.shared().setAnalyticsCollectionEnabled(true)
I do all of this initial settings in AppDelegate
something like
//init Firebase
FirebaseConfiguration.shared.setLoggerLevel(.min)
FirebaseApp.configure()
Fabric.with([Crashlytics.self])
let _ = FirebaseConfig.sharedInstance // This is a custom singelton class where I enable the analytics
In Scheme settings for your target you need to add -FIRAnalyticsDebugEnabled
As you can see I have also a disable option there, sometimes analytics goes crazy and spams the console , so I'd like to disable it with . -FIRDebugDisabled
Analytics clusters your events unless you specify it is a custom event.
For example I use following to tag the viewcontroller names
func logEvent(eventTitle:String , eventContent:String)
{
Analytics.logEvent(AnalyticsEventSelectContent, parameters: [
AnalyticsParameterItemID: "AppName-\(eventTitle)" as NSObject,
AnalyticsParameterItemName: eventTitle as NSObject,
AnalyticsParameterContentType: eventContent as NSObject
])
}
But int the firestore these are clustered under select_content section because I used AnalyticsEventSelectContent key when creating the log.
Under main events screen , select_content my view controlers logged with above function
4.There is a specific DebugView in the FirestoreConsole that works with a device, it updates every 60 seconds as long as settings for -FIRAnalyticsDebugEnabled is true in the scheme.
There is a significant delay in the Event Section of Firestore console, I don't know why this happens, but sometimes there is a delay up to 15 - 30 mins. Havent researched that issue yet, it really doesnt bother me.
Just follow https://firebase.google.com/docs/analytics/ios/start
To enable Analytics Debug mode on your development device, specify the following command line argument in Xcode :
-FIRDebugEnabled
It works perfectly for Simulator and device.
Note: For react-native debugging, launch app from xcode with the selected scheme and not with 'yarn ios', then it works perfectly for Simulator also

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.

Non-fatal errors not showing in Crashlytics

I was testing the non-fatal error functionality of Crashlytics and can't seem to get the recorded errors to appear in Crashlytics.
I did initialize Crashlytics in AppDelegate like this:
Fabric.with([Crashlytics.self])
And I test send error like this (the test code is in viewDidLoad method):
let error = NSError(domain: "myDomain", code: 1000, userInfo: nil)
Crashlytics.sharedInstance().recordError(error)
But nothing shows up in the analytics. I tried to:
Restart application
Disconnect from debugger and run the application several times
Add regular crash using Crashlytics.sharedInstance().crash(). In that case only the fatal crash is reported
I waited 4 days for the data to show up
Versions:
Crashlytics (3.8.5)
Fabric (1.6.12)
Thanks
I found what was the problem:
The application code was embedded in a framework. My tip is that the non-fatal logs were saved in the framework's bundle not the main bundle. On the next start the main bundle was searched for logs but none was found, thus nothing was sent.
My solution was remove the app from framework as it was no longer needed in the project. I am not sure how this would be solved if you would need to keep the code in the framework.
Run the script which uploads DSYMS to Firebase. Typically this script is not executed in debug mode - check the Build Phases tab. If you use such configuration just try in AdHoc build.
Please check if you uploaded DSYM file with your build.

"[Crashlytics:Crash] Reporting is disabled"

I am getting the following error messages when our production iOS app initializes:
[Crashlytics] Version 3.8.4 (121)
[Crashlytics] Running on iOS Simulator (iPhone), 10.3.0 (16E195)
[Crashlytics:Crash] Reporting is disabled
[Crashlytics] Crash reporting could not be initialized
[Answers] Initialized
[Fabric] Initialized with kit versions: {
"com.twitter.answers.ios" = "1.3.4";
"com.twitter.crashlytics.ios" = "3.8.4";
"io.fabric.sdk.ios" = "1.6.11";
}
Every subsequent call to log an event gets the following error:
[Crashlytics:Crash] WARNING: CLSLog has been used before (or concurrently with)
Crashlytics initialization and cannot be recorded. The message was: ...
The non-production versions of the app work fine running the exact same code but with different bundleIDs. Normally when the app initializes for the first time, then I see the app populate in the Fabric dashboard, but in this case the app is not showing up.
We have an Android and an iOS version of the app, and they both use the same bundleID, so I am wondering if there is a conflict because of that? I see the Android version of the app in the dashboard, and it seems to be working properly. This is an app that originally was a Xamarin app that compiled to both platforms, neither of which incorporated Fabric/Crashlytics. We have now written native apps on each platform, and both are using Fabric/Crashlytics.
Since this is a pre-existing app in both stores, we do not have the option of changing either app’s bundleID.
Make sure you initialize Crashlytics with Fabric before calling any Crashlytics methods:
Fabric.with([Crashlytics.self])
One step I routinely miss is to make sure you've added the build phase on your target:
"${PODS_ROOT}/Fabric/run" ${FABRIC_API_KEY} ${FABRIC_BUILD_SECRET}
and either replace ${FABRIC_API_KEY} and ${FABRIC_BUILD_SECRET} with your key and secret or add custom build settings for each.
There are apparently cases where Crashlytics does not auto-activate new apps so that they show up under your list of apps, even though everything is coded correctly and data is going to their servers. In this case, send an email to Crashlytics support (support#fabric.io) that contains a copy of the info.plist entries for the app in question and they will activate it for you. I have had to do this several times, especially with app extensions.
When I finally traced it down in my situation, the error was entirely correct, but not obvious.
I saw these errors in various testing targets where the code we tested was using a custom logging wrapper which called CLSNSLogv(), but the test didn't actually go through the AppDelegate and therefore did NOT initialize Crashlytics. After trying a few things I was convinced that it worked when executed as an app, but in our configuration it was not working under the unit test configuration.
I'll likely alter our custom wrapper to bypass CLSNSLogv() during testing anyway. The biggest benefit of using that is when crashes occur on devices, so we won't be missing anything.

Firebase analytics for iOS Today extension(widget extension)

I tried to add firebase analytics in today extension.
So I input the configuration code
if (![FIRApp defaultApp]) {
[FIRApp configure];
}
in today extension's viewDidLoad.
And in the Xcode's Product > scheme > Edit scheme > Run > Arguments tab, I added the '-FIRAnalyticsDebugEnabled' as I want to show the logged event in firebase console's DebugView page. But, Any events didn't printed in the page.
The log added into App (not today extension) is checked in the DebugView in real time. What should I do to show today extension's log in firebase DebugView in real time?
From my experience, you can't use the app argument on the extension. I could add break point in the extension but I could see that the flag didn't have any effect on the extension. Therefore, extensions cannot send data in debug mode for now.
You can do it from code by calling setLoggerLevel method on FirebaseConfiguration singleton and set the logger level.
please see Firebase analytics documentation :
https://firebase.google.com/docs/reference/ios/firebasecore/api/reference/Classes
Enable debug mode by passing the -FIRDebugEnabled argument to the
application. You can add this argument in the application’s Xcode
scheme. When debug mode is enabled via -FIRDebugEnabled, further
executions of the application will also be in debug mode. In order to
return to default mode, you must explicitly disable the debug mode
with the application argument -FIRDebugDisabled.
It is also possible to change the default logging level in code by
calling setLoggerLevel: on the FIRConfiguration interface.

Resources