Skip to content

Commit 2ab6c4c

Browse files
authored
Crashlytics: Add support for setUserId (#59)
1 parent fd825f4 commit 2ab6c4c

File tree

16 files changed

+109
-54
lines changed

16 files changed

+109
-54
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ fastlane/test_output
7070

7171
buildboth.sh
7272
Pods
73-
GoogleService-Info.plist

crashlytics/src/androidMain/kotlin/co/touchlab/crashkios/crashlytics/CrashlyticsCallsActual.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ actual class CrashlyticsCallsActual : CrashlyticsCalls {
2828
}
2929
}
3030
}
31+
32+
override fun setUserId(identifier: String) {
33+
FirebaseCrashlytics.getInstance().setUserId(identifier)
34+
}
3135
}

crashlytics/src/commonMain/kotlin/co/touchlab/crashkios/crashlytics/CrashlyticsCalls.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface CrashlyticsCalls {
55
fun sendHandledException(throwable: Throwable)
66
fun sendFatalException(throwable: Throwable)
77
fun setCustomValue(key: String, value: Any)
8+
fun setUserId(identifier: String)
89
}
910

10-
expect class CrashlyticsCallsActual() : CrashlyticsCalls
11+
expect class CrashlyticsCallsActual() : CrashlyticsCalls

crashlytics/src/commonMain/kotlin/co/touchlab/crashkios/crashlytics/CrashlyticsKotlin.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ object CrashlyticsKotlin {
2020
fun setCustomValue(key: String, value: Any) {
2121
implementation.setCustomValue(key, value)
2222
}
23+
24+
fun setUserId(identifier: String) {
25+
implementation.setUserId(identifier)
26+
}
2327
}
2428

2529
/**
@@ -46,4 +50,8 @@ internal object EmptyCalls : CrashlyticsCalls {
4650
override fun setCustomValue(key: String, value: Any) {
4751

4852
}
53+
54+
override fun setUserId(identifier: String) {
55+
56+
}
4957
}

crashlytics/src/darwinMain/kotlin/co/touchlab/crashkios/crashlytics/CrashlyticsCallsActual.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ actual class CrashlyticsCallsActual : CrashlyticsCalls {
2727
override fun setCustomValue(key: String, value: Any) {
2828
FIRCrashlytics.crashlytics().setCustomValue(value, key)
2929
}
30+
31+
override fun setUserId(identifier: String) {
32+
FIRCrashlytics.crashlytics().setUserID(identifier)
33+
}
3034
}

crashlytics/src/include/FIRCrashlytics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
- (void)setCustomValue:(nullable id)value forKey:(NSString *)key;
2828
- (void)recordExceptionModel:(FIRExceptionModel *)exceptionModel
2929
NS_SWIFT_NAME(record(exceptionModel:));
30+
- (void)setUserID:(nullable NSString *)userID;
3031
@end

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kotlin.code.style=official
55
SONATYPE_HOST=DEFAULT
66
RELEASE_SIGNING_ENABLED=true
77
GROUP=co.touchlab.crashkios
8-
VERSION_NAME=0.8.4
8+
VERSION_NAME=0.8.5
99

1010
POM_URL=https://github.com/touchlab/CrashKios
1111
POM_DESCRIPTION=Kotlin Native iOS Crash Report Library

samples/sample-crashlytics/app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ android {
2929
resources.excludes.add("META-INF/*.kotlin_module")
3030
}
3131
buildTypes {
32-
getByName("release") {
32+
getByName("release") {
3333
isMinifyEnabled = false
3434
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
3535
}

samples/sample-crashlytics/app/src/main/java/co/touchlab/crashkiossamplecrashlog/MainActivity.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
package co.touchlab.crashkiossamplecrashlog
1212

13-
import androidx.appcompat.app.AppCompatActivity
1413
import android.os.Bundle
14+
import androidx.appcompat.app.AppCompatActivity
1515
import co.touchlab.crashkiossample.CrashBot
1616
import co.touchlab.crashkiossample.SampleCommon
1717
import co.touchlab.crashkiossamplecrashlog.databinding.ActivityMainBinding
@@ -23,10 +23,13 @@ class MainActivity : AppCompatActivity() {
2323
setContentView(binding.root)
2424

2525
val sampleCommon = SampleCommon()
26-
binding.clickCount.setOnClickListener{
27-
sampleCommon.onClick()
26+
binding.userId.setOnClickListener {
27+
sampleCommon.setUserId("123")
28+
}
29+
binding.clickCount.setOnClickListener {
30+
sampleCommon.onClick()
2831
}
29-
binding.logException.setOnClickListener{
32+
binding.logException.setOnClickListener {
3033
sampleCommon.logException()
3134
}
3235
binding.crash.setOnClickListener {
Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!--
3-
~ Copyright (c) 2021 Touchlab
3+
~ Copyright (c) 2023 Touchlab
44
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
55
~ You may obtain a copy of the License at
66
~
@@ -10,36 +10,43 @@
1010
-->
1111

1212
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
13-
xmlns:app="http://schemas.android.com/apk/res-auto"
14-
xmlns:tools="http://schemas.android.com/tools"
15-
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:orientation="vertical"
18-
android:layout_gravity="center_vertical"
19-
tools:context=".MainActivity">
13+
xmlns:tools="http://schemas.android.com/tools"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:orientation="vertical"
17+
android:layout_gravity="center_vertical"
18+
tools:context=".MainActivity">
2019

2120
<Button
22-
android:id="@+id/click_count"
23-
android:layout_width="wrap_content"
24-
android:layout_height="wrap_content"
25-
android:layout_margin="32dp"
26-
android:layout_gravity="center_horizontal"
27-
android:text="Click Count" />
21+
android:id="@+id/user_id"
22+
android:layout_width="wrap_content"
23+
android:layout_height="wrap_content"
24+
android:layout_margin="32dp"
25+
android:layout_gravity="center_horizontal"
26+
android:text="Set User Id"/>
2827

2928
<Button
30-
android:id="@+id/log_exception"
31-
android:layout_width="wrap_content"
32-
android:layout_height="wrap_content"
33-
android:layout_gravity="center_horizontal"
34-
android:layout_margin="32dp"
35-
android:text="Log Exception" />
29+
android:id="@+id/click_count"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_margin="32dp"
33+
android:layout_gravity="center_horizontal"
34+
android:text="Click Count"/>
3635

3736
<Button
38-
android:id="@+id/crash"
39-
android:layout_width="wrap_content"
40-
android:layout_height="wrap_content"
41-
android:layout_gravity="center_horizontal"
42-
android:layout_margin="32dp"
43-
android:text="Crash" />
37+
android:id="@+id/log_exception"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_gravity="center_horizontal"
41+
android:layout_margin="32dp"
42+
android:text="Log Exception"/>
43+
44+
<Button
45+
android:id="@+id/crash"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_gravity="center_horizontal"
49+
android:layout_margin="32dp"
50+
android:text="Crash"/>
4451

4552
</LinearLayout>

0 commit comments

Comments
 (0)