-
-
Notifications
You must be signed in to change notification settings - Fork 364
Expand file tree
/
Copy pathRNSentrySDK.m
More file actions
78 lines (63 loc) · 2.4 KB
/
Copy pathRNSentrySDK.m
File metadata and controls
78 lines (63 loc) · 2.4 KB
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
#import "RNSentrySDK.h"
#import "RNSentryStart.h"
#import <Sentry/PrivateSentrySDKOnly.h>
#import <Sentry/Sentry.h>
static NSString *SENTRY_OPTIONS_RESOURCE_NAME = @"sentry.options";
static NSString *SENTRY_OPTIONS_RESOURCE_TYPE = @"json";
@implementation RNSentrySDK
+ (void)start
{
[self startWithConfigureOptions:nil];
}
+ (void)startWithConfigureOptions:(void (^)(SentryOptions *options))configureOptions
{
NSString *path = [[NSBundle mainBundle] pathForResource:SENTRY_OPTIONS_RESOURCE_NAME
ofType:SENTRY_OPTIONS_RESOURCE_TYPE];
[self start:path configureOptions:configureOptions];
}
+ (void)start:(NSString *)path configureOptions:(void (^)(SentryOptions *options))configureOptions
{
NSError *readError = nil;
NSError *parseError = nil;
NSError *optionsError = nil;
NSData *_Nullable content = nil;
if (path != nil) {
content = [NSData dataWithContentsOfFile:path options:0 error:&readError];
}
NSDictionary *dict = nil;
if (content != nil) {
dict = [NSJSONSerialization JSONObjectWithData:content options:0 error:&parseError];
}
if (readError != nil) {
NSLog(@"[RNSentry] Failed to load options from %@, with error: %@", path,
readError.localizedDescription);
}
if (parseError != nil) {
NSLog(@"[RNSentry] Failed to parse JSON from %@, with error: %@", path,
parseError.localizedDescription);
}
SentryOptions *options = nil;
if (dict != nil) {
options = [RNSentryStart createOptionsWithDictionary:dict error:&optionsError];
}
if (optionsError != nil) {
NSLog(@"[RNSentry] Failed to parse options from %@, with error: %@", path,
optionsError.localizedDescription);
}
if (options == nil) {
// Fallback in case that options file could not be parsed.
NSError *fallbackError = nil;
options = [PrivateSentrySDKOnly optionsWithDictionary:@{} didFailWithError:&fallbackError];
if (fallbackError != nil) {
NSLog(@"[RNSentry] Failed to create fallback options with error: %@",
fallbackError.localizedDescription);
}
}
[RNSentryStart updateWithReactDefaults:options];
if (configureOptions != nil) {
configureOptions(options);
}
[RNSentryStart updateWithReactFinals:options];
[RNSentryStart startWithOptions:options];
}
@end