Last active
November 15, 2022 13:32
-
-
Save vhugogarcia/ae60e3a1f902da1e285d5b54fde2acb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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