Twitter Fabric in Xamarin.iOS
By Mike Irving - Published: 30/8/2016

A few weeks back, I posted a blog on how to integrate Crashlytics and Answers into Android apps built with Xamarin.

Here is the corresponding blog post, for iOS Xamarin Apps.

Firstly, good news in that the process is a little simpler for iOS. Something I have found to be the case when integrating third-party SDKs into projects.

Again, a two step process, Xcode first to add a dummy project into the Fabric system. Then over to Xamarin to make our real app assume that role.


Xcode

Install Xcode, if you don't already have it, then download and install Fabric for iOS, from the official Fabric Download page.

Start Xcode, and create a Blank project with same Bundle Identifier as your real app, and make the version number 1.0 (or less that your projected new release or app update).

Then "Add Fabric" from the Xcode menu / button.

Once the Fabric wizard comes up, add Crashlytics and Answers, then build and run your app.

Run a few times on the iPhone or iPad Simulator, and head over to Fabric in your browser, to confirm we are up and running.

If we're happy at this stage, that's it for Xcode.. close it down, but keep the iOS Simulator ready for use with Xamarin.

You can also close the Fabric macOS app.


Xamarin Studio, or Visual Studio

Load up your project, then import the MonoTouch.Fabric and MonoTouch.Fabric.Crashlytics NuGet packages.

Add References to the two new packages, in your project.


Info.plist

Info.plist - add Dictionary "Fabric" containing String "APIKey", which is your Fabric/Crashlytics API Key.

Update your Version and Build numbers to numbers above those from the Dummy Xcode project.


AppDelegate.cs

In the App Delegate file, add the following declarations.

using MonoTouch.Fabric;
using MonoTouch.Fabric.Crashlytics;
using System.Threading.Tasks;
using System.IO;


Then at the top of FinishedLaunching, add...

Setup.EnableCrashReporting(() =>
   {
      var crashlytics = Crashlytics.SharedInstance;
      crashlytics.DebugMode = true;
      Crashlytics.StartWithAPIKey("your-api-key");
      Fabric.With(new NSObject[]{ crashlytics });
      AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
      {
         Setup.CaptureManagedInfo(e.ExceptionObject);
         Setup.CaptureStackFrames(e.ExceptionObject);
         Setup.ThrowExceptionAsNative(e.ExceptionObject);
      };
      TaskScheduler.UnobservedTaskException += (sender, e) =>
      {
         Setup.CaptureManagedInfo(e.Exception);
         Setup.CaptureStackFrames(e.Exception);
         Setup.ThrowExceptionAsNative(e.Exception);
      };
   }, Path.GetFileNameWithoutExtension(typeof(AppDelegate).Module.Name));


Build and Run

Build and Run your project, and be amazed as your App communicates with Answers!

Providing you followed the step about incrementing the build/version numbers, your actual App Icon should hop accross into the Fabric dashboard too.


View Blog Entries...
Page: 1, 2, 3, 4, 5, 6, 7, 8