Created
June 24, 2016 23:05
-
-
Save fcy/7945e26777569d32c205d492c79b47e8 to your computer and use it in GitHub Desktop.
Revisions
-
fcy created this gist
Jun 24, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #import <Foundation/Foundation.h> /* How To Enable CrashlyticsAdapter * * # On the App Target * * Initialize Crashlytics as usual and pass the real Crashlytics instance to the adapter: * * [Fabric with:@[[Crashlytics class]]]; * [CrashlyticsAdapter with:[Crashlytics sharedInstance]]; * * # On Libraries That Need Crashlytics * * Just use `[CrashlyticsAdapter sharedInstance]` instead of `CrashlyticsKit` or `[Crashlytics sharedInstance]`. * */ @protocol CrashlyticsAPI - (void)setUserIdentifier:(NSString *)identifier; - (void)setObjectValue:(NSObject *)value forKey:(NSString *)key; - (void)recordError:(NSError *)error; - (void)recordError:(NSError *)error withAdditionalUserInfo:(NSDictionary<NSString *, NSObject *> *)userInfo; @end @interface CrashlyticsAdapter : NSObject <CrashlyticsAPI> + (instancetype)sharedInstance; + (void)with:(id<CrashlyticsAPI>)crashlytics; - (instancetype)init NS_UNAVAILABLE; @end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ #import "CrashlyticsAdapter.h" @interface CrashlyticsAdapter () @property (nonatomic, strong) id<CrashlyticsAPI> crashlytics; @end @implementation CrashlyticsAdapter static CrashlyticsAdapter *sharedInstance; + (instancetype)sharedInstance { return sharedInstance; } + (void)with:(id<CrashlyticsAPI>)crashlytics { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[CrashlyticsAdapter alloc] initWithCrashlytics:crashlytics]; }); } - (instancetype)initWithCrashlytics:(id<CrashlyticsAPI>)crashlytics { self = [super init]; if (self) { self.crashlytics = crashlytics; } return self; } #pragma mark - Crashlytics API Delegation - (void)setUserIdentifier:(NSString *)identifier { [self.crashlytics setUserIdentifier:identifier]; } - (void)setObjectValue:(NSObject *)value forKey:(NSString *)key { [self.crashlytics setObjectValue:value forKey:key]; } - (void)recordError:(NSError *)error { [self.crashlytics recordError:error]; } - (void)recordError:(NSError *)error withAdditionalUserInfo:(NSDictionary<NSString *, NSObject *> *)userInfo { [self.crashlytics recordError:error withAdditionalUserInfo:userInfo]; } @end