Skip to content

Commit d5b4a6f

Browse files
committed
feat: return boolean on configure(), bump major
1 parent 11bf106 commit d5b4a6f

File tree

8 files changed

+71
-83
lines changed

8 files changed

+71
-83
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Use the native Firebase SDK in Axway Titanium. This repository is part of the [Titanium Firebase](https://github.com/hansemannn/titanium-firebase) project.
33

44
## Requirements
5-
- [x] Titanium SDK 6.3.0+
5+
- [x] Titanium SDK 7.0.0+
66

77
## Download
88
- [x] [Stable release](https://github.com/hansemannn/titanium-firebase-core/releases)
@@ -14,11 +14,11 @@ Use the native Firebase SDK in Axway Titanium. This repository is part of the [T
1414

1515
#### Methods
1616

17-
##### `configure()`
17+
##### `configure() -> Boolean`
1818

1919
Configure Firebase without additional parameters.
2020

21-
<b>Android</b>: returns false if it was already configured or if there was an error. Calling `deleteInstanceId()` can be used to re-configure it again.
21+
Returns `false` if it was already configured or if there was an error. Calling `deleteInstanceId()` can be used to re-configure it.
2222

2323
##### `configure(parameters)`
2424

android/Resources/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

android/manifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 2.3.1
5+
version: 3.0.0
66
apiversion: 4
77
architectures: arm64-v8a armeabi-v7a x86
88
description: titanium-firebase-core
99
author: Hans Knoechel
1010
license: Apache 2
11-
copyright: Copyright (c) 2017 by Axway Appcelerator
11+
copyright: Copyright (c) 2017-present by Hans Knoechel
1212

1313
# these should not be edited
1414
name: titanium-firebase-core

android/platform/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

ios/Classes/FirebaseCoreModule.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
#import "TiModule.h"
99

10-
@interface FirebaseCoreModule : TiModule {
11-
}
10+
@interface FirebaseCoreModule : TiModule
1211

13-
- (void)configure:(id)arguments;
12+
- (NSNumber *)configure:(id)arguments;
1413

1514
- (void)deleteInstanceId:(id)callback;
1615

ios/Classes/FirebaseCoreModule.m

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,47 +37,48 @@ - (void)startup
3737

3838
#pragma Public APIs
3939

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
4848
{
4949
if ([FIRApp defaultApp] != nil) {
5050
DebugLog(@"[DEBUG] The defaultApp of FirebaseCore has already been configured, skipping initialization.");
51-
return;
51+
return @(NO);
5252
}
53-
53+
5454
if (!arguments || [arguments count] == 0) {
5555
[FIRApp configure];
56-
return;
56+
return @(YES);
5757
}
58-
58+
5959
NSDictionary *payload = [arguments objectAtIndex:0];
6060
FIROptions *options = [FIROptions defaultOptions];
61-
61+
6262
NSString *name = [payload objectForKey:@"name"];
6363
NSString *file = [payload objectForKey:@"file"];
6464
NSString *googleAppID = [payload objectForKey:@"googleAppID"];
6565
NSString *GCMSenderID = [payload objectForKey:@"GCMSenderID"];
66-
66+
6767
// Check if plist file provided first
6868
if (file != nil) {
6969
if (![[file pathExtension] isEqualToString:@"plist"]) {
7070
NSLog(@"[ERROR] The \"file\" property has to include a .plist file, e.g. \"GoogleService-Info.plist\"");
71+
return @(NO);
7172
}
7273
options = [[FIROptions alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[file stringByDeletingPathExtension]
7374
ofType:[file pathExtension]]];
74-
75+
7576
// Check for google-credentials next
7677
} else if (googleAppID != nil && GCMSenderID != nil) {
7778
NSString *path = [[NSBundle mainBundle] pathForResource:[file stringByDeletingPathExtension] ofType:[file pathExtension]];
7879
options = [[FIROptions alloc] initWithGoogleAppID:googleAppID
7980
GCMSenderID:GCMSenderID];
80-
81+
8182
// Try to set any other properties provided if nothing else works
8283
} else {
8384
ADD_TO_OPTIONS_IF_SET(payload, @"APIKey", options);
@@ -90,54 +91,60 @@ - (void)configure:(id)arguments
9091
ADD_TO_OPTIONS_IF_SET(payload, @"deepLinkURLScheme", options);
9192
ADD_TO_OPTIONS_IF_SET(payload, @"storageBucket", options);
9293
}
93-
94+
9495
if (name != nil) {
9596
[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);
97106
}
98-
99-
[FIRApp configureWithOptions:options];
100107
}
101108

102109
- (void)deleteInstanceId:(id)callback
103110
{
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+
}];
117124
}
118125

119126
- (void)deleteToken:(id)arguments
120127
{
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+
}];
141148
}
142149

143150
@end

ios/manifest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
# this is your module manifest and used by Titanium
33
# during compilation, packaging, distribution, etc.
44
#
5-
version: 1.3.0
5+
version: 2.0.0
66
apiversion: 2
77
architectures: armv7 arm64 i386 x86_64
88
description: titanium-firebase-core
99
author: Hans Knoechel
1010
license: Apache 2
11-
copyright: Copyright (c) 2017 by Axway Appcelerator
11+
copyright: Copyright (c) 2017-present by Hans Knoechel
1212

1313
# these should not be edited
1414
name: titanium-firebase-core
1515
moduleid: firebase.core
1616
guid: 67251823-11de-4439-8150-56cad62a55eb
1717
platform: iphone
18-
minsdk: 6.3.0.GA
18+
minsdk: 7.0.0

ios/titanium.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
55
//
66
//
7-
TITANIUM_SDK_VERSION = 6.2.2.GA
7+
TITANIUM_SDK_VERSION = 7.4.1.GA
88

99

1010
//

0 commit comments

Comments
 (0)