This article details how you can install Crashlytics to a Xamarin iOS applicaton and link it to Fabric. This content also appears in my Using Crashlytics With Xamarin Apps post where I walk through all the steps required to distribute Xamarin apps for beta testing with Fabric.
XAMARIN PROJECT SETUP (OPTIONAL)
Lets create our Xamarin project, if you already have a working app you can just ignore this step, just make sure the App Identifier in your info.plist is the same as what you made in your developer account.
Create a new Xamarin project, it can be a shared or pcl (or even prism) this bit doesn’t matter. Create the app with whatever name you want and copy across your bundle identifier.
Once your project has been created you are ready to hop into Xcode and configure Fabric.
CREATING AN XCODE PROJECT WITH FABRIC
Create a new Xcode project, you will need to do this even if you have a fully functioning Xamarin App. What we are going to do is create an app with the same Bundle ID as our Xamarin App and trick fabric.
In Xcode go to File -> New -> Project and create a Single View Application. Call the project something and fill in your details, however what you call it at this point is irrelevant. We will need to change the Bundle ID manually anyway so call it whatever you want.
Note, It’s probably a good idea to label your app as iOS so that you don’t get confused which app is which later!
After your project has been created you will be greeted with the info.plist, change the Bundle ID to what you used in your developer account.
You don’t need to worry about code signing in this project, only the bundle id.
Now you will need to open up the Fabric Mac app and sign in.
Once you are logged in you should go onto the main menu and click + New App.
Now we just follow the installation instructions given to use by Fabric and integrate crashlytics with the Xcode project app. First select the Xcode project that you just created (it should be the top hit on the fabric browser but you could use the finder to be safe). Select the project and hit next.
Now Fabric will ask you what products you wish to install, select Crashlytics.
The first thing you will need to do is add a run script to your Xcode project.
Copy the command that Fabric gives you and navigate to your Xcode project. In your Xcode project file navigate to Build Phases.
Click on the + button (top left, beneath the app icon) and add a new Run Script Phase
Now open up the new run script and copy in the text that Fabric gave you.
Now build your project (⌘+B) and Fabric should notice and prompt you to install some frameworks. Drag the frameworks into your Xcode project and accept any dialogue boxes that appear.
Now the frameworks we need should have been installed into our Xcode project, you should now see them in the Navigation Window.
Now Fabric wants you to add some code to the app delegate, copy this across.
Your App Delegate should look like this:
Click next on the Fabric app and now run your Xcode project (⌘+R).
Once your app is running the Fabric app should notice and it will notify you that you are done. At this point we are done with our Xcode project, we have successfully created the Xamarin iOS app in our Fabric account. Any iOS builds will be distributed via this project.
LINKING YOUR XAMARIN PROJECT TO FABRIC
Open up your Xamarin project and go into the iOS folder (we only need to deal with this folder, not the pcl / shared / android / other folders). Once again CHECK that your Bundle ID is THE SAME as what you entered into your developer account. I cannot stress how important this is.
Once you are sure you have the right bundle id you should open the info.plist of your Xamarin app up in Xcode (which is probably the easiest way to edit this file).
COPY FABRIC API KEY INTO YOUR XAMARIN INFO.PLIST
Next open up the info.plist of the Xcode project that we just linked to Fabric. The script we ran on the Xcode project added a reference to our fabrics API key, so we need to add this to our Xamarin app. You can simply copy and paste the row across from the Xcode project to your Xamarin project. Make sure you save this file and close it.
Now we are ready to integrate Fabric & Crashlytics into our Xamarin.iOS project. On packages add the following Nuget packages: Fabric, Crashlytics.
Both packages are published by an author named “Michel Moreira”, make sure you get the latest versions of each. You only need to install there packages to the iOS project (which is handy).
Open up the AppDelegate.cs and add the following import statements:
using FabricSdk; using CrashlyticsKit;
And inside the DidFinishLaunchingWithOptions method add the following code:
Your app delegate should now look something like this (if you made a blank project)
Run your app on a simulator and you should notice logs published by Crashlytics, Congratulations you have now linked Crashlytics to your Xamarin.iOS app!
At this point you no longer need the Xcode project you made however I wouldn’t recommend deleting it (just in case). I would find a place to archive it and put it up on the shelf.
If this article helped you, please let me know by commenting below.
You can find me on the following sites: