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

martn_st picture martn_st · Nov 26, 2014 · Viewed 8k times · Source

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.

Answer

martn_st picture martn_st · Nov 26, 2014

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")
    }