@@ -37,47 +37,48 @@ - (void)startup
37
37
38
38
#pragma Public APIs
39
39
40
- #define ADD_TO_OPTIONS_IF_SET (payload, property, options ) \
41
- { \
42
- if ([payload objectForKey: property] != nil ) { \
43
- [options setValue: [payload objectForKey: property] forKey: property]; \
44
- } \
45
- }
46
-
47
- - (void )configure : (id )arguments
40
+ #define ADD_TO_OPTIONS_IF_SET (payload, property, options ) \
41
+ { \
42
+ if ([payload objectForKey: property] != nil ) { \
43
+ [options setValue: [payload objectForKey: property] forKey: property]; \
44
+ } \
45
+ } \
46
+
47
+ - (NSNumber * )configure : (id )arguments
48
48
{
49
49
if ([FIRApp defaultApp ] != nil ) {
50
50
DebugLog (@" [DEBUG] The defaultApp of FirebaseCore has already been configured, skipping initialization." );
51
- return ;
51
+ return @( NO ) ;
52
52
}
53
-
53
+
54
54
if (!arguments || [arguments count ] == 0 ) {
55
55
[FIRApp configure ];
56
- return ;
56
+ return @( YES ) ;
57
57
}
58
-
58
+
59
59
NSDictionary *payload = [arguments objectAtIndex: 0 ];
60
60
FIROptions *options = [FIROptions defaultOptions ];
61
-
61
+
62
62
NSString *name = [payload objectForKey: @" name" ];
63
63
NSString *file = [payload objectForKey: @" file" ];
64
64
NSString *googleAppID = [payload objectForKey: @" googleAppID" ];
65
65
NSString *GCMSenderID = [payload objectForKey: @" GCMSenderID" ];
66
-
66
+
67
67
// Check if plist file provided first
68
68
if (file != nil ) {
69
69
if (![[file pathExtension ] isEqualToString: @" plist" ]) {
70
70
NSLog (@" [ERROR] The \" file\" property has to include a .plist file, e.g. \" GoogleService-Info.plist\" " );
71
+ return @(NO );
71
72
}
72
73
options = [[FIROptions alloc ] initWithContentsOfFile: [[NSBundle mainBundle ] pathForResource: [file stringByDeletingPathExtension ]
73
74
ofType: [file pathExtension ]]];
74
-
75
+
75
76
// Check for google-credentials next
76
77
} else if (googleAppID != nil && GCMSenderID != nil ) {
77
78
NSString *path = [[NSBundle mainBundle ] pathForResource: [file stringByDeletingPathExtension ] ofType: [file pathExtension ]];
78
79
options = [[FIROptions alloc ] initWithGoogleAppID: googleAppID
79
80
GCMSenderID: GCMSenderID];
80
-
81
+
81
82
// Try to set any other properties provided if nothing else works
82
83
} else {
83
84
ADD_TO_OPTIONS_IF_SET (payload, @" APIKey" , options);
@@ -90,54 +91,60 @@ - (void)configure:(id)arguments
90
91
ADD_TO_OPTIONS_IF_SET (payload, @" deepLinkURLScheme" , options);
91
92
ADD_TO_OPTIONS_IF_SET (payload, @" storageBucket" , options);
92
93
}
93
-
94
+
94
95
if (name != nil ) {
95
96
[FIRApp configureWithName: name options: options];
96
- return ;
97
+ return @(YES );
98
+ }
99
+
100
+ @try {
101
+ [FIRApp configureWithOptions: options];
102
+ return @(YES );
103
+ } @catch (NSException *exception) {
104
+ NSLog (@" [ERROR] Cannot configure Firebase: %@ " , exception.reason );
105
+ return @(NO );
97
106
}
98
-
99
- [FIRApp configureWithOptions: options];
100
107
}
101
108
102
109
- (void )deleteInstanceId : (id )callback
103
110
{
104
- ENSURE_SINGLE_ARG_OR_NIL (callback, KrollCallback);
105
-
106
- [[FIRInstanceID instanceID ] deleteIDWithHandler: ^(NSError *error) {
107
- if (callback != nil ) {
108
- NSDictionary *dict = nil ;
109
- if (error != nil ) {
110
- dict = @{ @" success" : @NO , @" error" : [error localizedDescription ] };
111
- } else {
112
- dict = @{ @" success" : @YES };
113
- }
114
- [callback call: @[dict] thisObject: nil ];
115
- }
116
- }];
111
+ ENSURE_SINGLE_ARG_OR_NIL (callback, KrollCallback);
112
+
113
+ [[FIRInstanceID instanceID ] deleteIDWithHandler: ^(NSError *error) {
114
+ if (callback != nil ) {
115
+ NSDictionary *dict = nil ;
116
+ if (error != nil ) {
117
+ dict = @{ @" success" : @( NO ) , @" error" : [error localizedDescription ] };
118
+ } else {
119
+ dict = @{ @" success" : @( YES ) };
120
+ }
121
+ [callback call: @[dict] thisObject: nil ];
122
+ }
123
+ }];
117
124
}
118
125
119
126
- (void )deleteToken : (id )arguments
120
127
{
121
- NSString *authorizedEntity;
122
- ENSURE_ARG_AT_INDEX (authorizedEntity, arguments, 0 , NSString );
123
-
124
- NSString *scope;
125
- ENSURE_ARG_AT_INDEX (scope, arguments, 1 , NSString );
126
-
127
- KrollCallback *callback;
128
- ENSURE_ARG_OR_NIL_AT_INDEX (callback, arguments, 2 , KrollCallback);
129
-
130
- [[FIRInstanceID instanceID ] deleteTokenWithAuthorizedEntity: authorizedEntity scope: scope handler: ^(NSError *error) {
131
- if (callback != nil ) {
132
- NSDictionary *dict = nil ;
133
- if (error != nil ) {
134
- dict = @{ @" success" : @NO , @" error" : [error localizedDescription ] };
135
- } else {
136
- dict = @{ @" success" : @YES };
137
- }
138
- [callback call: @[dict] thisObject: nil ];
139
- }
140
- }];
128
+ NSString *authorizedEntity;
129
+ ENSURE_ARG_AT_INDEX (authorizedEntity, arguments, 0 , NSString );
130
+
131
+ NSString *scope;
132
+ ENSURE_ARG_AT_INDEX (scope, arguments, 1 , NSString );
133
+
134
+ KrollCallback *callback;
135
+ ENSURE_ARG_OR_NIL_AT_INDEX (callback, arguments, 2 , KrollCallback);
136
+
137
+ [[FIRInstanceID instanceID ] deleteTokenWithAuthorizedEntity: authorizedEntity scope: scope handler: ^(NSError *error) {
138
+ if (callback != nil ) {
139
+ NSDictionary *dict = nil ;
140
+ if (error != nil ) {
141
+ dict = @{ @" success" : @( NO ) , @" error" : [error localizedDescription ] };
142
+ } else {
143
+ dict = @{ @" success" : @( YES ) };
144
+ }
145
+ [callback call: @[dict] thisObject: nil ];
146
+ }
147
+ }];
141
148
}
142
149
143
150
@end
0 commit comments