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.
Crashlytics support got in touch with me and provided these steps. I tested them and it now works for me iOS 8 app.
Add the Crashlytics Run Script Build Phase to your extension's target as well (copy / paste the same you added to your main app)
Add the
Crashlytics.framework
to your extension's linked libraries (e.g. simply check the extension target in its file inspector)Add the
Crashlytics.startWithAPIKey("yourApiKey")
to your extension's view controller'sinitWithCoder
method. (In Apple's today extension template it is calledTodayViewController
by default)> if you have no
initWithCoder
method yet, it should look like this afterwards:Answer from maremmle works also if you want to add Crashlytics to share extensions on iOS 8.0+. Just remember to put
[Crashlytics startWithAPIKey:@"apiKey"];
insideinit
method from your first ViewController.Here is official how-to described how to use Crashlytics in iOS Extensions:
viewController
'sinitWithCoder
methodFabric.with([Crashlytics.self])
And... you good to go!
Thanks for all instructions, it works fine in my Share Extension.
I did notice that for my Share Extension, the Fabric Answers dashboard did not show actual data for:
It does for the companion app. So I was wondering how the Answers SDK would determine this. The most logical seems to monitor the UIApplication notifications. Since the Lifecycle of an Extension is related to a ViewController, these UIApplication notifications are not posted. And hence Fabric doesn't know when the Extension is active.
So I implemented the following solution, which provides the above data in the Fabric Dashboard:
Please note there is a delay between the action on device, and when the data becomes visible in the Dashboard. Especially for Active Users. It takes around 20-30 seconds after the Extension is presented. But when the Extension is closed, it might take up to 5 minutes before the Active Users is decremented.
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:
and run
pod install
. And don't forget to setBuild Active Architecture Only
toNO
, or you may get linker errorsThen in your TodayViewController:
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