Skip to content

Latest commit

 

History

History
57 lines (46 loc) · 1.97 KB

README.md

File metadata and controls

57 lines (46 loc) · 1.97 KB

NSExceptionKt for Bugsnag

Installation

First make sure you have set up Bugsnag (v6.22.1 or above).

After that add and export the Kotlin dependency to your appleMain source set.

kotlin {
    iosArm64 { // and/or any other Apple target 
        binaries.framework {
            isStatic = true // it's recommended to use a static framework
            export("com.rickclephas.kmp:nsexception-kt-core:<version>")
        }
    }
    sourceSets {
        appleMain {
            dependencies {
                api("com.rickclephas.kmp:nsexception-kt-core:<version>")
            }
        }
    }
}

Now in your Xcode project add the NSExceptionKtBugsnag dependency and update your Bugsnag configuration logic with a call to NSExceptionKt.addReporter:

import Bugsnag
import NSExceptionKtBugsnag
import shared // This is your shared Kotlin module

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil
    ) -> Bool {
        let config = BugsnagConfiguration.loadConfig()
        NSExceptionKt.addReporter(.bugsnag(config))
        Bugsnag.start(with: config)
        return true
    }
}

That's all, now go and crash that app!

Implementation details

Bugsnag has built-in support for caused by errors.

However, Bugsnag does store multiple fatal exceptions, which would normally result in a logged fatal Kotlin termination. To prevent this fatal Kotlin termination from being logged NSExceptionKt sets a feature flag after the unhandled Kotlin exception has been logged, an addOnSendError filter makes sure to drop the errors contain said feature flag.