Skip to content

Latest commit

 

History

History
364 lines (228 loc) · 10.1 KB

File metadata and controls

364 lines (228 loc) · 10.1 KB

@capacitor-firebase/crashlytics

⚡️ Capacitor plugin for Firebase Crashlytics.

Installation

npm install @capacitor-firebase/crashlytics
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS).

Android

See Add the Firebase Crashlytics plugin to your app and follow the instructions to set up your app correctly.

Variables

This plugin will use the following project variables (defined in your app’s variables.gradle file):

  • $firebaseCrashlyticsVersion version of com.google.firebase:firebase-crashlytics (default: 18.2.9)

iOS

See Set up Xcode to automatically upload dSYM files and follow the instructions to set up Xcode correctly.
Attention: The path used in section 4.c of the guide should be:

"${PODS_ROOT}/FirebaseCrashlytics/run"

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Usage

import { FirebaseCrashlytics } from '@capacitor-firebase/crashlytics';

const crash = async () => {
  await FirebaseCrashlytics.crash({ message: 'Test' });
};

const setCustomKey = async () => {
  await FirebaseCrashlytics.setCustomKey({
    key: 'page',
    value: 'home',
    type: 'string',
  });
};

const setUserId = async () => {
  await FirebaseCrashlytics.setUserId({
    userId: '123',
  });
};

const log = async () => {
  await FirebaseCrashlytics.log({
    message: 'Test',
  });
};

const setEnabled = async () => {
  await FirebaseCrashlytics.setEnabled({
    enabled: true,
  });
};

const isEnabled = async () => {
  const { enabled } = await FirebaseCrashlytics.isEnabled();
  return enabled;
};

const didCrashOnPreviousExecution = async () => {
  const { crashed } = await FirebaseCrashlytics.didCrashOnPreviousExecution();
  return crashed;
};

const sendUnsentReports = async () => {
  await FirebaseCrashlytics.sendUnsentReports();
};

const deleteUnsentReports = async () => {
  await FirebaseCrashlytics.deleteUnsentReports();
};

const recordException = async () => {
  await FirebaseCrashlytics.recordException({
    message: 'This is a non-fatal message.',
  });
};

API

crash(...)

crash(options: CrashOptions) => Promise<void>

Forces a crash to test the implementation.

Only available for Android and iOS.

Param Type
options CrashOptions

setCustomKey(...)

setCustomKey(options: SetCustomKeyOptions) => Promise<void>

Sets a custom key and value that is associated with subsequent fatal and non-fatal reports.

Only available for Android and iOS.

Param Type
options SetCustomKeyOptions

setUserId(...)

setUserId(options: SetUserIdOptions) => Promise<void>

Sets a user ID (identifier) that is associated with subsequent fatal and non-fatal reports.

Only available for Android and iOS.

Param Type
options SetUserIdOptions

log(...)

log(options: LogOptions) => Promise<void>

Adds a custom log message that is sent with your crash data to give yourself more context for the events leading up to a crash.

Only available for Android and iOS.

Param Type
options LogOptions

setEnabled(...)

setEnabled(options: SetEnabledOptions) => Promise<void>

Enables/disables automatic data collection. The value does not apply until the next run of the app.

Only available for Android and iOS.

Param Type
options SetEnabledOptions

isEnabled()

isEnabled() => Promise<IsEnabledResult>

Returns whether or not automatic data collection is enabled.

Only available for iOS.

Returns: Promise<IsEnabledResult>


didCrashOnPreviousExecution()

didCrashOnPreviousExecution() => Promise<DidCrashOnPreviousExecutionResult>

Returns whether the app crashed during the previous execution.

Only available for Android and iOS.

Returns: Promise<DidCrashOnPreviousExecutionResult>


sendUnsentReports()

sendUnsentReports() => Promise<void>

Uploads any unsent reports to Crashlytics. When automatic data collection is enabled, Crashlytics automatically uploads reports at startup.

Only available for Android and iOS.


deleteUnsentReports()

deleteUnsentReports() => Promise<void>

Deletes any unsent reports on the device.

Only available for Android and iOS.


recordException(...)

recordException(options: RecordExceptionOptions) => Promise<void>

Records a non-fatal report to send to Crashlytics.

Only available for Android and iOS.

Param Type
options RecordExceptionOptions

Interfaces

CrashOptions

Prop Type
message string

SetCustomKeyOptions

Prop Type
key string
value string | number | boolean
type 'string' | 'boolean' | 'long' | 'double' | 'int' | 'float'

SetUserIdOptions

Prop Type
userId string

LogOptions

Prop Type
message string

SetEnabledOptions

Prop Type
enabled boolean

IsEnabledResult

Prop Type
enabled boolean

DidCrashOnPreviousExecutionResult

Prop Type
crashed boolean

RecordExceptionOptions

Prop Type Description
message string
code number Error code within a specific error domain. Only available for iOS.
domain string A string containing the error domain. Only available for iOS.

Test your implementation

Here you can find more information on how to test the Firebase Crashlytics implementation. Among other things, you will find information on how to correctly adjust the project's debug settings under iOS and how to test it out.

If you get obfuscated crash reports for iOS, make sure you have initialized Crashlytics correctly and take a look at this guide, which provides some ways to troubleshoot if Crashlytics can't find your app's dSYM.

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

This plugin is based on the Capacitor Community Firebase Crashlytics plugin. Thanks to everyone who contributed to the project!