|
1 | | -Initialize Sentry in your main application entry point, typically in your `main()` function or `App` composable: |
| 1 | +1. Add a function to initialize Sentry to your shared module (`commonMain`). |
| 2 | +2. Call the function in your iOS and Android app modules. |
2 | 3 |
|
3 | | -```kotlin {filename:App.kt} |
| 4 | +```kotlin {filename:SentrySetup.kt}{tabTitle: commonMain} |
4 | 5 | import io.sentry.kotlin.multiplatform.Sentry |
5 | | -import androidx.compose.runtime.Composable |
6 | | - |
7 | | -@Composable |
8 | | -fun App() { |
9 | | - // Initialize Sentry when your app starts |
10 | | - Sentry.init { options -> |
11 | | - options.dsn = "___PUBLIC_DSN___" |
12 | | - // Adds request headers and IP for users, for more info visit: |
13 | | - // https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/data-collected/ |
14 | | - options.sendDefaultPii = true |
| 6 | + |
| 7 | +fun initializeSentry() { |
| 8 | + Sentry.init { options -> |
| 9 | + options.dsn = "___PUBLIC_DSN___" |
| 10 | + // Adds request headers and IP for users, for more info visit: |
| 11 | + // https://docs.sentry.io/platforms/kotlin/guides/kotlin-multiplatform/data-management/data-collected/ |
| 12 | + options.sendDefaultPii = true |
| 13 | + } |
| 14 | +} |
| 15 | +``` |
| 16 | +```swift {tabTitle: iosApp} |
| 17 | +import ComposeApp // Replace this with the name of the shared framework |
| 18 | + |
| 19 | +@main |
| 20 | +struct iOSApp: App { |
| 21 | + init() { |
| 22 | + SentrySetupKt.initializeSentry() |
15 | 23 | } |
16 | | - |
17 | | - // ... your compose UI content |
| 24 | + var body: some Scene { |
| 25 | + WindowGroup { |
| 26 | + ContentView() |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// OR alternatively in AppDelegate: |
| 32 | + |
| 33 | + |
| 34 | +func application( |
| 35 | + _ application: UIApplication, |
| 36 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil |
| 37 | +) -> Bool { |
| 38 | + SentrySetupKt.initializeSentry() |
| 39 | + return true |
| 40 | +} |
| 41 | + |
| 42 | +``` |
| 43 | +```kotlin {filename:MainActivity.kt}{tabTitle: androidApp} |
| 44 | +import your.kmp.app.initializeSentry |
| 45 | + |
| 46 | +class YourApplication : Application() { |
| 47 | + override fun onCreate() { |
| 48 | + super.onCreate() |
| 49 | + initializeSentry() |
| 50 | + } |
18 | 51 | } |
19 | | -``` |
| 52 | +``` |
0 commit comments