Skip to content

Commit d737b36

Browse files
committed
Updates to ordering of loading
1 parent 5683916 commit d737b36

File tree

31 files changed

+430
-260
lines changed

31 files changed

+430
-260
lines changed

ios/Firestack.xcodeproj/project.pbxproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
D97261661D550CF5000F703F /* GoogleInterchangeUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261651D550CF5000F703F /* GoogleInterchangeUtilities.framework */; };
1818
D97261691D550D03000F703F /* GoogleIPhoneUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261681D550D03000F703F /* GoogleIPhoneUtilities.framework */; };
1919
D972616B1D550D07000F703F /* GoogleNetworkingUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D972616A1D550D07000F703F /* GoogleNetworkingUtilities.framework */; };
20-
D972616D1D550D0B000F703F /* GoogleParsingUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D972616C1D550D0B000F703F /* GoogleParsingUtilities.framework */; };
2120
D972616F1D550D0F000F703F /* GoogleSymbolUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D972616E1D550D0F000F703F /* GoogleSymbolUtilities.framework */; };
2221
D97261711D550D13000F703F /* GoogleUtilities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261701D550D13000F703F /* GoogleUtilities.framework */; };
2322
D97261771D550D81000F703F /* FirebaseAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261761D550D81000F703F /* FirebaseAnalytics.framework */; };
@@ -31,6 +30,7 @@
3130
D97261C51D551BF0000F703F /* libicucore.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261C41D551BF0000F703F /* libicucore.tbd */; };
3231
D97261C71D551BF5000F703F /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261C61D551BF5000F703F /* CFNetwork.framework */; };
3332
D97261C91D551BFF000F703F /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D97261C81D551BFF000F703F /* AddressBook.framework */; };
33+
D98A11F41D8D167D004DB865 /* AppDelegate+Firestack.m in Sources */ = {isa = PBXBuildFile; fileRef = D98A11F31D8D167D004DB865 /* AppDelegate+Firestack.m */; };
3434
D9A8C7A41D7E54C900142F94 /* libPods-Firestack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D95036B81D19C90300F7094D /* libPods-Firestack.a */; };
3535
D9D62E7C1D6D86FD003D826D /* FirestackStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = D9D62E7B1D6D86FD003D826D /* FirestackStorage.m */; };
3636
D9D62E801D6D8717003D826D /* FirestackAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = D9D62E7F1D6D8717003D826D /* FirestackAuth.m */; };
@@ -99,6 +99,8 @@
9999
D97261C41D551BF0000F703F /* libicucore.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libicucore.tbd; path = usr/lib/libicucore.tbd; sourceTree = SDKROOT; };
100100
D97261C61D551BF5000F703F /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
101101
D97261C81D551BFF000F703F /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
102+
D98A11F21D8D167D004DB865 /* AppDelegate+Firestack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "AppDelegate+Firestack.h"; path = "Firestack/AppDelegate+Firestack.h"; sourceTree = "<group>"; };
103+
D98A11F31D8D167D004DB865 /* AppDelegate+Firestack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "AppDelegate+Firestack.m"; path = "Firestack/AppDelegate+Firestack.m"; sourceTree = "<group>"; };
102104
D9CFBE441D531058002623BF /* buildScript.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = buildScript.sh; sourceTree = "<group>"; };
103105
D9D62E7A1D6D86FD003D826D /* FirestackStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FirestackStorage.h; path = Firestack/FirestackStorage.h; sourceTree = "<group>"; };
104106
D9D62E7B1D6D86FD003D826D /* FirestackStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FirestackStorage.m; path = Firestack/FirestackStorage.m; sourceTree = "<group>"; };
@@ -128,7 +130,6 @@
128130
D97261661D550CF5000F703F /* GoogleInterchangeUtilities.framework in Frameworks */,
129131
D97261691D550D03000F703F /* GoogleIPhoneUtilities.framework in Frameworks */,
130132
D972616B1D550D07000F703F /* GoogleNetworkingUtilities.framework in Frameworks */,
131-
D972616D1D550D0B000F703F /* GoogleParsingUtilities.framework in Frameworks */,
132133
D972616F1D550D0F000F703F /* GoogleSymbolUtilities.framework in Frameworks */,
133134
D97261711D550D13000F703F /* GoogleUtilities.framework in Frameworks */,
134135
0A4200BEE17F6884883BB2E7 /* libPods-Firestack.a in Frameworks */,
@@ -176,6 +177,7 @@
176177
58B511D21A9E6C8500147676 = {
177178
isa = PBXGroup;
178179
children = (
180+
D98A11F61D8D1683004DB865 /* Extensions */,
179181
D96290351D6D145F0099A3EC /* Modules */,
180182
D9CFBE441D531058002623BF /* buildScript.sh */,
181183
D950369C1D19C77400F7094D /* Firestack.h */,
@@ -223,6 +225,15 @@
223225
name = Modules;
224226
sourceTree = "<group>";
225227
};
228+
D98A11F61D8D1683004DB865 /* Extensions */ = {
229+
isa = PBXGroup;
230+
children = (
231+
D98A11F21D8D167D004DB865 /* AppDelegate+Firestack.h */,
232+
D98A11F31D8D167D004DB865 /* AppDelegate+Firestack.m */,
233+
);
234+
name = Extensions;
235+
sourceTree = "<group>";
236+
};
226237
/* End PBXGroup section */
227238

228239
/* Begin PBXNativeTarget section */
@@ -336,6 +347,7 @@
336347
D9D62E7C1D6D86FD003D826D /* FirestackStorage.m in Sources */,
337348
D962903F1D6D15B00099A3EC /* FirestackErrors.m in Sources */,
338349
D950369E1D19C77400F7094D /* Firestack.m in Sources */,
350+
D98A11F41D8D167D004DB865 /* AppDelegate+Firestack.m in Sources */,
339351
D90882D61D89C18C00FB6742 /* FirestackCloudMessaging.m in Sources */,
340352
D96290851D6D28B80099A3EC /* FirestackDatabase.m in Sources */,
341353
);

ios/Firestack/AppDelegate+Firestack.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface AppDelegate : UIResponder
4+
5+
@end
6+

ios/Firestack/AppDelegate+Firestack.m

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#import <objc/runtime.h>
2+
#import "AppDelegate+Firestack.h"
3+
#import "Firebase.h"
4+
#import "Firestack.h"
5+
#import "FirestackEvents.h"
6+
7+
@implementation AppDelegate (Firestack)
8+
9+
+ (void) load
10+
{
11+
static dispatch_once_t onceToken;
12+
dispatch_once(&onceToken, ^{
13+
Class class = [self class];
14+
15+
SEL originalSelector = @selector(application:didFinishLaunchingWithOptions:);
16+
SEL swizzledSelector = @selector(swizzled_application:didFinishLaunchingWithOptions:);
17+
18+
Method originalMethod = class_getInstanceMethod(class, originalSelector);
19+
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
20+
21+
BOOL didAddMethod =
22+
class_addMethod(class,
23+
originalSelector,
24+
method_getImplementation(swizzledMethod),
25+
method_getTypeEncoding(swizzledMethod));
26+
27+
if (didAddMethod) {
28+
class_replaceMethod(class,
29+
swizzledSelector,
30+
method_getImplementation(originalMethod),
31+
method_getTypeEncoding(originalMethod));
32+
} else {
33+
method_exchangeImplementations(originalMethod, swizzledMethod);
34+
}
35+
});
36+
}
37+
38+
- (BOOL) swizzled_application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
39+
{
40+
BOOL res = [self swizzled_application:application didFinishLaunchingWithOptions:launchOptions];
41+
[FIRApp configure];
42+
[self setupListeners];
43+
return res;
44+
}
45+
46+
- (void) dealloc
47+
{
48+
[[NSNotificationCenter defaultCenter] removeObserver:self];
49+
}
50+
51+
- (void) setupListeners
52+
{
53+
// Post notification that we've initialized Firebase
54+
[[NSNotificationCenter defaultCenter]
55+
postNotificationName:kFirestackInitialized
56+
object:nil];
57+
58+
// Add listener for when firestack the app reloads
59+
[[NSNotificationCenter defaultCenter] addObserver:self
60+
selector:@selector(reloadFirestack)
61+
name:RCTReloadNotification
62+
object:nil];
63+
}
64+
65+
- (void) reloadFirestack
66+
{
67+
// TODO:
68+
}
69+
70+
@end

ios/Firestack/Firestack.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@
99
#import "RCTBridgeModule.h"
1010
#import "RCTEventDispatcher.h"
1111
#import "RCTEventEmitter.h"
12+
#import "AppDelegate+Firestack.h"
1213

1314
@interface Firestack : RCTEventEmitter <RCTBridgeModule> {
1415
FIRAuthStateDidChangeListenerHandle authListenerHandle;
1516
}
1617

17-
+ (void) registerForNotification:(NSString *) typeStr andToken:(NSData *)deviceToken;
18-
+ (void) setup:(UIApplication *) application;
18+
// + (void) registerForNotification:(NSString *) typeStr andToken:(NSData *)deviceToken;
19+
// + (void) setup:(UIApplication *) application;
20+
21+
+ (void) reloadFirestack;
22+
+ (void) initializeFirestack:(Firestack *) instance;
23+
+ (instancetype) sharedInstance;
24+
- (FIRApp *) firebaseApp;
25+
26+
- (void) debugLog:(NSString *)title
27+
msg:(NSString *)msg;
28+
1929

2030
@property (nonatomic) BOOL debug;
2131
@property (atomic) BOOL configured;

ios/Firestack/Firestack.m

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,84 @@
44
// Copyright © 2016 Facebook. All rights reserved.
55
//
66

7+
#import <objc/runtime.h>
8+
79
#import "Firestack.h"
810
#import "FirestackErrors.h"
911
#import "FirestackEvents.h"
10-
#import "FirestackCloudMessaging.h"
12+
#import "FirestackAnalytics.h"
13+
// #import "FirestackCloudMessaging.h"
1114

1215
@import Firebase;
1316

17+
static Firestack *_sharedInstance = nil;
18+
1419
@implementation Firestack
20+
1521
typedef void (^UserWithTokenResponse)(NSDictionary *, NSError *);
1622

1723
- (void)dealloc
1824
{
19-
NSLog(@"Dealloc called on Firestack");
20-
[[FIRApp defaultApp] deleteApp:^(BOOL success) {
21-
if (success) {
22-
NSLog(@"Successfully removed app");
23-
} else {
24-
NSLog(@"Unsuccessfully cleaned up all");
25-
}
26-
}];
25+
NSLog(@"Dealloc called on Firestack: %@", self);
26+
[[NSNotificationCenter defaultCenter] removeObserver:self];
27+
}
28+
29+
- (instancetype) init {
30+
self = [super init];
31+
if (self) {
32+
NSLog(@"Initializing Firestack: %@", self);
33+
[Firestack initializeFirestack:self];
34+
}
35+
return self;
2736
}
2837

29-
+ (void) setup:(UIApplication *) application
38+
+ (void) initializeFirestack:(Firestack *) instance
3039
{
31-
[FirestackCloudMessaging setup:application];
40+
NSLog(@"Shared instance created on Firestack: %@", instance);
41+
// [FIRApp configureWithOptions:finalOptions];
42+
43+
_sharedInstance = instance;
44+
45+
[[NSNotificationCenter defaultCenter] addObserver:self
46+
selector:@selector(reloadFirestack)
47+
name:RCTReloadNotification
48+
object:nil];
49+
50+
// [[NSNotificationCenter defaultCenter]
51+
// postNotificationName:RCTReloadNotification
52+
// object:nil
53+
// userInfo:nil];
54+
55+
// [[NSNotificationCenter defaultCenter] addObserver:self
56+
// selector:@selector(firestackConfigured:)
57+
// name:kFirestackInitialized
58+
// object:instance];
3259
}
3360

61+
+ (instancetype) sharedInstance
62+
{
63+
return _sharedInstance;
64+
}
65+
66+
+ (void) reloadFirestack
67+
{
68+
// Reloading firestack
69+
[[Firestack sharedInstance] debugLog:@"Firestack"
70+
msg:@"Reloading firestack"];
71+
}
72+
73+
- (FIRApp *) firebaseApp
74+
{
75+
return [FIRApp defaultApp];
76+
}
77+
78+
3479
RCT_EXPORT_MODULE(Firestack);
3580

3681
RCT_EXPORT_METHOD(configureWithOptions:(NSDictionary *) opts
3782
callback:(RCTResponseSenderBlock)callback)
3883
{
84+
NSLog(@"dispatch once on configure");
3985
dispatch_async(dispatch_get_main_queue(),^{
4086
// Are we debugging, yo?
4187
self.debug = [opts valueForKey:@"debug"] != nil ? YES : NO;
@@ -172,13 +218,14 @@ + (void) setup:(UIApplication *) application
172218
storageBucket:[props valueForKey:@"STORAGE_BUCKET"]
173219
deepLinkURLScheme:[props valueForKey:@"DEEP_LINK_SCHEME"]];
174220

175-
// Save configuration option
176-
// NSDictionary *cfg = [self getConfig];
177-
// [cfg setValuesForKeysWithDictionary:props];
178-
179-
// if (!self.configured) {
180-
181-
[FIRApp configureWithOptions:finalOptions];
221+
NSLog(@"Configuring firestack instance: %@", self);
222+
// Save configuration option
223+
// NSDictionary *cfg = [self getConfig];
224+
// [cfg setValuesForKeysWithDictionary:props];
225+
// self.configuration = cfg;
226+
227+
[Firestack initializeFirestack:self];
228+
self.configured = YES;
182229
callback(@[[NSNull null], props]);
183230
}
184231
@catch (NSException *exception) {
@@ -312,17 +359,12 @@ - (void) debugLog:(NSString *)title
312359
{
313360
if (self.debug) {
314361
NSLog(@"%@: %@", title, msg);
315-
// [self sendJSEvent:DEBUG_EVENT
316-
// props:@{
317-
// @"name": title,
318-
// @"message": msg
319-
// }];
320362
}
321363
}
322364

323365
// Not sure how to get away from this... yet
324366
- (NSArray<NSString *> *)supportedEvents {
325-
return @[DEBUG_EVENT, AUTH_CHANGED_EVENT];
367+
return @[INITIALIZED_EVENT, DEBUG_EVENT, AUTH_CHANGED_EVENT];
326368
}
327369

328370
- (void) sendJSEvent:(NSString *)title

ios/Firestack/FirestackAnalytics.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@
66
// Copyright © 2016 Facebook. All rights reserved.
77
//
88

9+
#import "Firestack.h"
10+
#import "FirestackEvents.h"
911
#import "FirestackAnalytics.h"
1012

1113
@import FirebaseAnalytics;
1214

1315
@implementation FirestackAnalytics
1416

15-
RCT_EXPORT_MODULE(FirestackAnalytics);
16-
1717
- (void)dealloc
1818
{
1919
[[NSNotificationCenter defaultCenter] removeObserver:self];
2020
}
2121

22+
RCT_EXPORT_MODULE(FirestackAnalytics);
23+
24+
// Implementation
2225
RCT_EXPORT_METHOD(logEventWithName:(NSString *)name
2326
props:(NSDictionary *)props
2427
callback:(RCTResponseSenderBlock) callback)
2528
{
26-
NSLog(@"logEventWithName called: %@ and %@", name, props);
29+
NSString *debugMsg = [NSString stringWithFormat:@"%@: %@ with %@",
30+
@"FirestackAnalytics", name, props];
31+
[[Firestack sharedInstance] debugLog:@"logEventWithName called"
32+
msg:debugMsg];
33+
2734
[FIRAnalytics logEventWithName:name parameters:props];
2835
callback(@[[NSNull null], @YES]);
2936
}

ios/Firestack/FirestackEvents.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
1313
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
1414
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
15+
#define FIRESTACK_QUEUE_NAME "io.fullstack.firestack.WorkerQueue"
16+
17+
static NSString *const kFirestackInitialized = @"FirestackInitializedEvent";
18+
static NSString *const INITIALIZED_EVENT = @"firestackInitialized";
1519

1620
static NSString *const AUTH_CHANGED_EVENT = @"listenForAuth";
1721
static NSString *const DEBUG_EVENT = @"debug";

0 commit comments

Comments
 (0)