1

There's some existing questions and info dotted around about this (for example How to use Crashlytics with iOS / OS X today view extensions?) but they are very very old, using APIs that no longer exist, have contradictory information, and generally a mess.

My question is simple - is it possible to run Crashlytics in an extension? Specifically a notification service extension?

If anybody has any up to date step by step instructions I'd be grateful. I've tried a few experimentations but nothing working. But actually I don't see how it could actually even work - because crashes in an app are uploaded to the dashboard next time the app runs. But how would an app know that a crash occured within an extension if Crashlytics was added to the extension? If the app and the extension are using a shared group then crashlytics info could be shared between the extension and the app via a file in the group, and yet in none of the answers/references regarding regarding crashlyics/extensions is this aspect ever mentioned.

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378
  • Mostly yes, but depends what extension. Crashlytics Watch Extensions are included in the Quickstart [repo](https://github.com/firebase/quickstart-ios/tree/master/crashlytics/CrashlyticsSwiftUIExample_(watchOS)_Extension), so this suggests it's possible: – Pranav Kasetti Oct 21 '21 at 18:21

1 Answers1

1

I've successfully done it for extensions, but it is tricky (and I don't know if it's officially supported). You're right the main app doesn't know when an extension crashes, so you need to make sure you start Crashlytics from the extension when the process starts. For NSE, I start it in the didReceive(:) function since that's the starting point of the process.

Each extension also has it's own separate Google-Info.plist file so it's reported separately from the main app.

johnny
  • 1,434
  • 1
  • 15
  • 26
  • 1
    So its only going to be able to upload crash information if and when the next time the extension runs after the crash presumably. How does it have enough time to make the http connection and upload the data? What if there's a lot of crash info to upload and its a slow connection and the extension only runs for a very short amount of time? – Gruntcakes Oct 21 '21 at 17:45
  • Crashlytics completely controls that, so the details of that are unknown to me. At least in my case, HTTP requests are getting made within NSE anyway to resolve all the notification details, so if Crashlytics makes one, it shouldn't be an issue. I assume they have some kind of a batching / buffering system if there is a large build up of crashes to send, but as far as I know it's not something that Crashlytics publicizes. – johnny Oct 21 '21 at 18:19