### Complete Multi-Platform Framework Setup Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Example Gradle build configuration for a Kotlin Multiplatform project, showing how to export the NSExceptionKt core dependency for Apple and macOS targets. ```APIDOC ## Complete Multi-Platform Framework Setup A complete build configuration for a Kotlin Multiplatform project targeting multiple Apple platforms with NSExceptionKt core dependency properly exported. ```kotlin // build.gradle.kts plugins { alias(libs.plugins.kotlin.multiplatform) } kotlin { jvmToolchain(11) jvm() // iOS targets listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true export("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } // macOS targets (optional) listOf( macosX64(), macosArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true export("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } sourceSets { appleMain { dependencies { api("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } } } ``` ``` -------------------------------- ### Swift Package Manager Installation Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Instructions for installing NSExceptionKt using Swift Package Manager, including options for installing only Crashlytics or Bugsnag dependencies. ```APIDOC ## Swift Package Manager Installation Add NSExceptionKt to your Xcode project using Swift Package Manager. Use the specialized package names to avoid downloading unnecessary dependencies when you only need one crash reporting integration. ```swift // Package.swift or Xcode SPM integration // Repository URL: https://github.com/nickclephas/NSExceptionKt // For Crashlytics only (avoids Bugsnag dependency): // Use version tag with "-spm-crashlytics" suffix // Example: "1.0.8-spm-crashlytics" // For Bugsnag only (avoids Firebase dependency): // Use version tag with "-spm-bugsnag" suffix // Example: "1.0.8-spm-bugsnag" // Xcode: File > Add Packages > Enter repository URL // Select the appropriate library: // - NSExceptionKtCrashlytics for Firebase Crashlytics // - NSExceptionKtBugsnag for Bugsnag ``` ``` -------------------------------- ### Swift Package Manager Installation Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Configure SPM dependencies to include only the necessary crash reporting integrations. ```swift // Package.swift or Xcode SPM integration // Repository URL: https://github.com/nickclephas/NSExceptionKt // For Crashlytics only (avoids Bugsnag dependency): // Use version tag with "-spm-crashlytics" suffix // Example: "1.0.8-spm-crashlytics" // For Bugsnag only (avoids Firebase dependency): // Use version tag with "-spm-bugsnag" suffix // Example: "1.0.8-spm-bugsnag" // Xcode: File > Add Packages > Enter repository URL // Select the appropriate library: // - NSExceptionKtCrashlytics for Firebase Crashlytics // - NSExceptionKtBugsnag for Bugsnag ``` -------------------------------- ### Throwing Kotlin Exceptions for Testing Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Provides code examples for creating and throwing test exceptions in shared Kotlin code to verify crash reporting functionality. ```APIDOC ## Throwing Kotlin Exceptions for Testing Create test exceptions in your shared Kotlin code to verify crash reporting is working correctly. Exceptions can include caused-by chains to test the full exception handling path. ### Kotlin Code Example (`shared/src/iosMain/kotlin/com/example/app/Crash.kt`) ```kotlin // shared/src/iosMain/kotlin/com/example/app/Crash.kt package com.example.app // Custom exception class for testing class TestException( message: String?, cause: Throwable? ): IllegalArgumentException(message, cause) // Function that throws a chained exception fun throwException() { return try { throwCauseException() } catch (e: Throwable) { throw TestException("Test exception 2", e) } } private fun throwCauseException() { throw IllegalArgumentException("Test exception 1") } ``` ### Swift Code Example (to trigger the crash) ```swift // Swift code to trigger the crash for testing import shared // Call from a button action or test scenario // This will crash the app and report to configured services Crash().throwException() ``` ``` -------------------------------- ### Configure Bugsnag Integration in AppDelegate Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Configure NSExceptionKt to report unhandled Kotlin exceptions to Bugsnag. The reporter must be added before `Bugsnag.start()`. This setup automatically configures Bugsnag for Kotlin exception chains and prevents duplicates. ```swift import Foundation import UIKit import Bugsnag import NSExceptionKtBugsnag import shared // Your shared Kotlin module class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { // Load Bugsnag configuration let config = BugsnagConfiguration.loadConfig() // Add NSExceptionKt reporter BEFORE starting Bugsnag // This configures Bugsnag to properly handle Kotlin exceptions NSExceptionKt.addReporter(.bugsnag(config)) // Start Bugsnag with the configured configuration Bugsnag.start(with: config) return true } } ``` -------------------------------- ### Configure Firebase Crashlytics Integration in AppDelegate Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Configure NSExceptionKt to report unhandled Kotlin exceptions to Firebase Crashlytics. The reporter must be added after Firebase is configured. This example uses the `.append` strategy for caused-by exceptions. ```swift import Foundation import UIKit import Firebase import NSExceptionKtCrashlytics import shared // Your shared Kotlin module class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { // Initialize Firebase first FirebaseApp.configure() // Add NSExceptionKt reporter with append strategy // This merges caused-by exceptions into a single stack trace NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .append)) return true } } ``` -------------------------------- ### Configuring Multi-Platform Frameworks Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Set up the build configuration in build.gradle.kts to export the NSExceptionKt core dependency. ```kotlin // build.gradle.kts plugins { alias(libs.plugins.kotlin.multiplatform) } kotlin { jvmToolchain(11) jvm() // iOS targets listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true export("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } // macOS targets (optional) listOf( macosX64(), macosArm64() ).forEach { it.binaries.framework { baseName = "shared" isStatic = true export("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } sourceSets { appleMain { dependencies { api("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } } } ``` -------------------------------- ### Configure Crash Reporting Tools Source: https://github.com/rickclephas/nsexceptionkt/blob/master/sample/README.md Add your GoogleService-Info.plist to the project and create an .xcconfig file with your Sentry and Bugsnag API keys and DSN. ```bash SENTRY_ORG = YOUR_ORG SENTRY_PROJECT = YOUR_PROJECT SENTRY_AUTH_TOKEN = YOUR_AUTH_TOKEN SENTRY_DSN = YOUR_DSN BUGSNAG_API_KEY = YOUR_API_KEY ``` -------------------------------- ### Using Both Crashlytics and Bugsnag Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Demonstrates how to register multiple crash reporters simultaneously with NSExceptionKt, allowing exceptions to be reported to different services. ```APIDOC ## Using Both Crashlytics and Bugsnag NSExceptionKt supports registering multiple reporters simultaneously. Each reporter wraps the unhandled exception hook, allowing exceptions to be reported to multiple crash reporting services before the program terminates. ```swift import Foundation import UIKit import Firebase import NSExceptionKtCrashlytics import Bugsnag import NSExceptionKtBugsnag import shared class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { // Setup Bugsnag first let bugsnagConfig = BugsnagConfiguration.loadConfig() NSExceptionKt.addReporter(.bugsnag(bugsnagConfig)) Bugsnag.start(with: bugsnagConfig) // Setup Firebase Crashlytics FirebaseApp.configure() NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .append)) return true } } ``` ``` -------------------------------- ### Configure Kotlin Multiplatform Dependency Source: https://github.com/rickclephas/nsexceptionkt/blob/master/NSExceptionKtBugsnag/README.md Add the nsexception-kt-core dependency to your appleMain source set and export it in your framework configuration. ```kotlin 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:") } } sourceSets { appleMain { dependencies { api("com.rickclephas.kmp:nsexception-kt-core:") } } } } ``` -------------------------------- ### Initialize Bugsnag Reporter in iOS Source: https://github.com/rickclephas/nsexceptionkt/blob/master/NSExceptionKtBugsnag/README.md Register the NSExceptionKt reporter within the Bugsnag configuration in your AppDelegate. ```swift 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 } } ``` -------------------------------- ### Using the addReporter API Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Register custom reporters or use the provided factories for Crashlytics and Bugsnag. ```kotlin // Kotlin API signature (from NSException.kt) public fun addReporter(reporter: NSExceptionKtReporterProtocol): Unit // The reporter protocol (from NSExceptionKtReporter.h) @protocol NSExceptionKtReporter @property (readonly) BOOL requiresMergedException; - (void)reportException:(NSArray * _Nonnull)exceptions; @end ``` ```swift // Swift usage - Crashlytics reporter factory NSExceptionKt.addReporter(.crashlytics( Crashlytics.crashlytics(), // optional: custom Crashlytics instance causedByStrategy: .append )) // Swift usage - Bugsnag reporter factory let config = BugsnagConfiguration.loadConfig() NSExceptionKt.addReporter(.bugsnag(config)) ``` -------------------------------- ### Add NSExceptionKt Core Dependency to build.gradle.kts Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Add the NSExceptionKt core dependency to your Kotlin Multiplatform project's `appleMain` source set. Ensure the dependency is exported from your framework for Swift accessibility. ```kotlin kotlin { iosArm64 { // and/or iosX64, iosSimulatorArm64, macosX64, macosArm64, tvosArm64, watchosArm64 binaries.framework { baseName = "shared" isStatic = true // recommended to use a static framework export("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } sourceSets { appleMain { dependencies { api("com.rickclephas.kmp:nsexception-kt-core:1.0.8") } } } } ``` -------------------------------- ### Throwing Kotlin Exceptions for Testing Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Define custom exceptions in shared Kotlin code and trigger them from Swift to verify reporting. ```kotlin // shared/src/iosMain/kotlin/com/example/app/Crash.kt package com.example.app // Custom exception class for testing class TestException( message: String?, cause: Throwable? ): IllegalArgumentException(message, cause) // Function that throws a chained exception fun throwException() { return try { throwCauseException() } catch (e: Throwable) { throw TestException("Test exception 2", e) } } private fun throwCauseException() { throw IllegalArgumentException("Test exception 1") } ``` ```swift // Swift code to trigger the crash for testing import shared // Call from a button action or test scenario // This will crash the app and report to configured services Crash().throwException() ``` -------------------------------- ### addReporter API Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Details the `addReporter` function, which is the core API for registering a crash reporter to receive unhandled Kotlin exceptions. ```APIDOC ## addReporter API The core function that registers a crash reporter to receive unhandled Kotlin exceptions. This function wraps Kotlin's unhandled exception hook so that exceptions are reported before the currently set hook is invoked and the program terminates. ```kotlin // Kotlin API signature (from NSException.kt) public fun addReporter(reporter: NSExceptionKtReporterProtocol): Unit // The reporter protocol (from NSExceptionKtReporter.h) @protocol NSExceptionKtReporter @property (readonly) BOOL requiresMergedException; - (void)reportException:(NSArray * _Nonnull)exceptions; @end ``` ### Swift Usage Examples **Crashlytics reporter factory:** ```swift NSExceptionKt.addReporter(.crashlytics( Crashlytics.crashlytics(), // optional: custom Crashlytics instance causedByStrategy: .append )) ``` **Bugsnag reporter factory:** ```swift let config = BugsnagConfiguration.loadConfig() NSExceptionKt.addReporter(.bugsnag(config)) ``` ``` -------------------------------- ### Crashlytics CausedByStrategy Options: Append (Recommended) Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt The `.append` strategy merges caused-by exceptions into the main Throwable, creating a single fatal exception with a stack trace that includes 'Caused by:' lines. This is the recommended approach for preserving full error context. ```swift import NSExceptionKtCrashlytics // Strategy 2: Append caused-by exceptions (recommended) // Causes are appended to the main Throwable as a single fatal exception // The stack trace includes "Caused by:" lines with full trace information NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .append)) ``` -------------------------------- ### Crashlytics CausedByStrategy Options: Log Non-Fatal Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Use the `.logNonFatal` strategy to log all caused-by exceptions as non-fatal entries before the main fatal exception. This results in multiple entries in the Crashlytics dashboard, providing a detailed but potentially fragmented view. ```swift import NSExceptionKtCrashlytics // Strategy 3: Log caused-by as non-fatal // All causes are logged as non-fatal exceptions before the main fatal exception // Results in multiple entries in Crashlytics dashboard NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .logNonFatal)) ``` -------------------------------- ### Registering Multiple Crash Reporters in AppDelegate Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Configure both Bugsnag and Firebase Crashlytics within the application delegate to ensure exceptions are reported to both services. ```swift import Foundation import UIKit import Firebase import NSExceptionKtCrashlytics import Bugsnag import NSExceptionKtBugsnag import shared class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { // Setup Bugsnag first let bugsnagConfig = BugsnagConfiguration.loadConfig() NSExceptionKt.addReporter(.bugsnag(bugsnagConfig)) Bugsnag.start(with: bugsnagConfig) // Setup Firebase Crashlytics FirebaseApp.configure() NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .append)) return true } } ``` -------------------------------- ### Configure Crashlytics Reporter in AppDelegate Source: https://github.com/rickclephas/nsexceptionkt/blob/master/NSExceptionKtCrashlytics/README.md Add the NSExceptionKtCrashlytics dependency to your Xcode project and configure Firebase Crashlytics reporting in your AppDelegate. ```swift import Firebase import NSExceptionKtCrashlytics import shared // This is your shared Kotlin module class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { FirebaseApp.configure() NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .append)) return true } } ``` -------------------------------- ### Crashlytics CausedByStrategy Options: Ignore Source: https://context7.com/rickclephas/nsexceptionkt/llms.txt Use the `.ignore` strategy to log only the main Throwable as a fatal exception in Crashlytics, omitting any caused-by exceptions. This is suitable when cause information is not critical. ```swift import NSExceptionKtCrashlytics // Strategy 1: Ignore caused-by exceptions // Only the main Throwable is logged as a fatal exception // Use when cause information is not critical NSExceptionKt.addReporter(.crashlytics(causedByStrategy: .ignore)) ``` -------------------------------- ### NSExceptionKt CausedByStrategy Enum Source: https://github.com/rickclephas/nsexceptionkt/blob/master/NSExceptionKtCrashlytics/README.md Defines strategies for handling caused-by exceptions with Firebase Crashlytics, which has limitations on reporting nested exceptions. ```swift public enum CausedByStrategy { /// Causes will be ignored, only the main Throwable is logged as a fatal exception. case ignore /// Causes are appended to the main Throwable and logged as a single fatal exception. case append /// All causes are logged as non-fatal exceptions before the main Throwable is logged as a fatal exception. case logNonFatal } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.