Skip to content

Instantly share code, notes, and snippets.

@vhugogarcia
Last active November 15, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vhugogarcia/ae60e3a1f902da1e285d5b54fde2acb5 to your computer and use it in GitHub Desktop.
Save vhugogarcia/ae60e3a1f902da1e285d5b54fde2acb5 to your computer and use it in GitHub Desktop.
using Firebase.Crashlytics;
#if IOS
using Foundation;
#else
using Firebase;
#endif
namespace DemoApp.Services.Firebase;
public interface IFirebaseCrashlyticsService
{
void Log(Exception ex);
}
public class FirebaseCrashlyticsService : IFirebaseCrashlyticsService
{
public void Log(Exception ex)
{
#if IOS
var errorInfo = new Dictionary<object, object> {
{ NSError.LocalizedDescriptionKey, NSBundle.MainBundle.GetLocalizedString(ex.Message, null) },
{ NSError.LocalizedFailureReasonErrorKey, NSBundle.MainBundle.GetLocalizedString ("Managed Failure", null) },
{ NSError.LocalizedRecoverySuggestionErrorKey, NSBundle.MainBundle.GetLocalizedString ("Recovery Suggestion", null) },
//{ "ProductId", "123456" }, you can append even custom information if needed
};
var error = new NSError(new NSString("NonFatalError"),
-1001,
NSDictionary.FromObjectsAndKeys(errorInfo.Values.ToArray(), errorInfo.Keys.ToArray(), errorInfo.Keys.Count));
Crashlytics.SharedInstance.RecordError(error);
#else
FirebaseCrashlytics.Instance.RecordException(Java.Lang.Throwable.FromException(ex));
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment