Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firebase-crashlytics/api/firebase-crashlytics.api
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public final class dev/gitlive/firebase/crashlytics/FirebaseCrashlytics {
public final fun didCrashOnPreviousExecution ()Z
public final fun log (Ljava/lang/String;)V
public final fun recordException (Ljava/lang/Throwable;)V
public final fun recordException (Ljava/lang/Throwable;Ljava/util/Map;)V
public final fun sendUnsentReports ()V
public final fun setCrashlyticsCollectionEnabled (Z)V
public final fun setCustomKey (Ljava/lang/String;D)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public actual class FirebaseCrashlytics internal constructor(internal val androi
public actual fun recordException(exception: Throwable) {
android.recordException(exception)
}
public actual fun recordException(exception: Throwable, customKeys: Map<String, Any>) {
android.recordException(exception, customKeys.toCustomKeysAndValues())
}
public actual fun log(message: String) {
android.log(message)
}
Expand Down Expand Up @@ -53,21 +56,21 @@ public actual class FirebaseCrashlytics internal constructor(internal val androi
android.setCustomKey(key, value)
}
public actual fun setCustomKeys(customKeys: Map<String, Any>) {
android.setCustomKeys(
Builder().apply {
customKeys.forEach { (key, value) ->
when (value) {
is String -> putString(key, value)
is Boolean -> putBoolean(key, value)
is Double -> putDouble(key, value)
is Float -> putFloat(key, value)
is Int -> putInt(key, value)
is Long -> putLong(key, value)
}
}
}.build(),
)
android.setCustomKeys(customKeys.toCustomKeysAndValues())
}

private fun Map<String, Any>.toCustomKeysAndValues() = Builder().apply {
forEach { (key, value) ->
when (value) {
is String -> putString(key, value)
is Boolean -> putBoolean(key, value)
is Double -> putDouble(key, value)
is Float -> putFloat(key, value)
is Int -> putInt(key, value)
is Long -> putLong(key, value)
}
}
}.build()
}

public actual open class FirebaseCrashlyticsException(message: String) : FirebaseException(message)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import platform.Foundation.NSLocalizedDescriptionKey
import dev.gitlive.firebase.Firebase
import dev.gitlive.firebase.FirebaseApp
import dev.gitlive.firebase.FirebaseException
import kotlin.Any
import kotlin.collections.Map

public val FirebaseCrashlytics.ios: FIRCrashlytics get() = FIRCrashlytics.crashlytics()

Expand All @@ -19,6 +21,10 @@ public actual class FirebaseCrashlytics internal constructor(internal val ios: F
public actual fun recordException(exception: Throwable) {
ios.recordError(exception.asNSError())
}
@Suppress("UNCHECKED_CAST")
public actual fun recordException(exception: Throwable, customKeys: Map<String, Any>) {
ios.recordError(exception.asNSError(), customKeys as Map<Any?, *>)
}
public actual fun log(message: String) {
ios.log(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public expect class FirebaseCrashlytics {
*/
public fun recordException(exception: Throwable)

/**
* Records a non-fatal report to send to Crashlytics.
*
* Combined with app level custom keys, the event is restricted to a maximum of 64 key/value
* pairs. New keys beyond that limit are ignored. Keys or values that exceed 1024 characters are
* truncated.
*
* The values of event keys override the values of app level custom keys if they're identical.
*
* @param exception a [Throwable] to be recorded as a non-fatal event.
* @param customKeys A dictionary of keys and the values to associate with the non fatal
* exception, in addition to the app level custom keys.
*/
public fun recordException(exception: Throwable, customKeys: Map<String, Any>)

/**
* Logs a message that's included in the next fatal, non-fatal, or ANR report.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ actual class FirebaseCrashlytics {
actual fun recordException(exception: Throwable) {
}

actual fun recordException(exception: Throwable, customKeys: Map<String, Any>) {
}

actual fun log(message: String) {
}

Expand Down