-
Notifications
You must be signed in to change notification settings - Fork 216
/
HockeyAppOSXProvider.m
108 lines (86 loc) · 3.15 KB
/
HockeyAppOSXProvider.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#import "HockeyAppOSXProvider.h"
#import <objc/message.h>
#ifdef AR_HOCKEYAPPOSX_EXISTS
#import <HockeySDK/HockeySDK.h>
#import <HockeySDK/BITCrashDetails.h>
#import <HockeySDK/BITCrashManager.h>
#import <HockeySDK/BITCrashManagerDelegate.h>
#endif
#define MAX_HOCKEY_LOG_MESSAGES 100
static BOOL
IsHockeySDKCompatibleForLogging(void)
{
static dispatch_once_t onceToken = 0;
static BOOL compatible = NO;
dispatch_once(&onceToken, ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
compatible = [[BITCrashDetails class] instancesRespondToSelector:@selector(appProcessIdentifier)];
#pragma clang diagnostic pop
});
return compatible;
}
@interface HockeyAppOSXProvider () <BITHockeyManagerDelegate, BITCrashManagerDelegate> {
NSString *_username;
NSString *_userEmail;
NSString *_liveIdentifier;
}
@end
@implementation HockeyAppOSXProvider
-(instancetype)initWithIdentifier:(NSString *)identifier {
self = [super init];
if (!self) return nil;
_liveIdentifier = identifier;
[self performSelector:@selector(startManager) withObject:nil afterDelay:0.5];
return self;
}
-(void)startManager {
[[BITHockeyManager sharedHockeyManager] configureWithIdentifier:_liveIdentifier delegate:self];
[[BITHockeyManager sharedHockeyManager] startManager];
#if HOCKEYSDK_FEATURE_AUTHENTICATOR
[[BITHockeyManager sharedHockeyManager].authenticator authenticateInstallation];
#endif
}
- (void)identifyUserWithID:(NSString *)userID andEmailAddress:(NSString *)email {
_username = userID;
_userEmail = email;
}
#pragma mark - Log breadcrumbs
- (void)remoteLog:(NSString *)message {
if (IsHockeySDKCompatibleForLogging()) {
[self localLog:message];
}
}
- (void)event:(NSString *)event withProperties:(NSDictionary *)properties {
if (IsHockeySDKCompatibleForLogging()) {
[self localLog:[NSString stringWithFormat:@"[%@] %@", event, properties]];
}
}
#pragma mark - BITHockeyManagerDelegate
- (NSString *)userNameForHockeyManager:(BITHockeyManager *)hockeyManager componentManager:(BITHockeyBaseManager *)componentManager {
return _username;
}
-(NSString *)userEmailForHockeyManager:(BITHockeyManager *)hockeyManager componentManager:(BITHockeyBaseManager *)componentManager {
return _userEmail;
}
#pragma mark - BITCrashManagerDelegate
- (NSString *)applicationLogForCrashManager:(BITCrashManager *)crashManager {
if (!IsHockeySDKCompatibleForLogging()) {
return @"";
}
BITCrashDetails *crashDetails = crashManager.lastSessionCrashDetails;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
NSUInteger processID = ((NSUInteger (*)(id, SEL))objc_msgSend)(crashDetails, @selector(appProcessIdentifier));
#pragma clang diagnostic pop
if (processID == 0) {
return @"";
}
NSArray *messages = [self messagesForProcessID:processID];
NSUInteger count = messages.count;
if (count > MAX_HOCKEY_LOG_MESSAGES) {
messages = [messages subarrayWithRange:NSMakeRange(count-MAX_HOCKEY_LOG_MESSAGES, MAX_HOCKEY_LOG_MESSAGES)];
}
return [messages componentsJoinedByString:@"\n"];
}
@end