Zoli
Zoli

Reputation: 910

How to clear/remove firebase Crashlytics custom keys?

You can associate arbitrary key/value pairs with your crash reports by FirebaseCrashlytics.getInstance().setCustomKey(key, value)

Fine.
But how can I revert those when I don't need anymore?

Consider following code:

// report 'ex_1' with "info" key
FirebaseCrashlytics.getInstance().setCustomKey("info", "abc");
FirebaseCrashlytics.getInstance().recordException(ex_1);

//Now I want to clear custom keys, so I want to report 'ex_2' without "info"
//FirebaseCrashlytics.getInstance().REMOVECustomKey("info");
FirebaseCrashlytics.getInstance().recordException(ex_2);

Upvotes: 15

Views: 1793

Answers (2)

bodich
bodich

Reputation: 2215

Th next code will literally remove the value. You will not see it anymore in reports, it will disappear. It works exactly like Dictionary works, when you set nil value, this key is being removed.

Crashlytics.crashlytics().setCustomValue(nil, forKey: "key")

Upvotes: 3

Dhananjay Suresh
Dhananjay Suresh

Reputation: 1286

I don't see anything in the SDK that allows for this. They should really offer some way to clear the Custom Keys but the SDK does not allow for nullable values either.

The way I went around it was just to override the one-shot custom keys with a 0.

// Set key
FirebaseCrashlytics.getInstance().setCustomKey("key", "value")

// Clear key
FirebaseCrashlytics.getInstance().setCustomKey("key", 0)

It is not the cleanest approach but at least you know those values got reset.

Upvotes: 0

Related Questions