Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Crashlytics with iOS / OS X today view extensions?

Since today extensions run as separated a process I am sure they will not log any crashes out of the box. I assume we need to initialize Crashlytics on the widget separately. E.g. in the viewDidLoad method of the TodayViewController.

  • Is anybody already using Crashlytics inside any iOS / OS X extensions? If so, how did you implemented it?
  • I am also wondering if it would make sense to create a separate app in Crashlytics just for the extension.
like image 410
martn_st Avatar asked Nov 26 '14 09:11

martn_st


3 Answers

Crashlytics support got in touch with me and provided these steps. I tested them and it now works for me iOS 8 app.

  1. Add the Crashlytics Run Script Build Phase to your extension's target as well (copy / paste the same you added to your main app)

  2. Add the Crashlytics.framework to your extension's linked libraries (e.g. simply check the extension target in its file inspector)

  3. Add the Crashlytics.startWithAPIKey("yourApiKey") to your extension's view controller's initWithCodermethod. (In Apple's today extension template it is called TodayViewController by default)

    > if you have no initWithCoder method yet, it should look like this afterwards:

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        Crashlytics.startWithAPIKey("yourApiKey")
    }
    
like image 116
martn_st Avatar answered Sep 26 '22 07:09

martn_st


Here is Twitter's own guide to implementing it:

https://twittercommunity.com/t/integrate-fabric-crashlytics-with-ios-8-extension/28905

So, copy the libraries, for instance if you're using CocoaPods you can add Fabric and Crashlytics to the Extension target:

In Podfile:

target :TodayExtension do
  pod 'Fabric'
  pod 'Crashlytics'
end

and run pod install. And don't forget to set Build Active Architecture Only to NO, or you may get linker errors

Then in your TodayViewController:

#import <Fabric/Fabric.h>
#import <Crashlytics/Crashlytics.h>

...

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    [Fabric with:@[CrashlyticsKit]];
    return self;
}

and copy the Fabric Run Script in build phases to your Today Extension target, and copy the Fabric entry from the info plist from the main application into your Today Extension's info plist

like image 8
andrrs Avatar answered Sep 26 '22 07:09

andrrs


Here is official how-to described how to use Crashlytics in iOS Extensions:

  • Add this line to your viewController's initWithCoder method Fabric.with([Crashlytics.self])
  • Copy the "Fabric" Dictionary from your main app's Info.plist and paste into your extension's Info.plist.
  • Copy/paste the Run Script Build Phase from your main app's target into your extension's Run Script Build Phase.

And... you good to go!

like image 6
Valentin Shergin Avatar answered Sep 23 '22 07:09

Valentin Shergin