2017-10-26 10:55:07 +00:00
|
|
|
#import "RNFirebaseUtil.h"
|
|
|
|
|
|
|
|
@implementation RNFirebaseUtil
|
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
static NSString *const DEFAULT_APP_DISPLAY_NAME = @"[DEFAULT]";
|
|
|
|
static NSString *const DEFAULT_APP_NAME = @"__FIRAPP_DEFAULT";
|
|
|
|
|
|
|
|
+ (FIRApp *)getApp:(NSString *)appDisplayName {
|
|
|
|
NSString *appName = [RNFirebaseUtil getAppName:appDisplayName];
|
|
|
|
return [FIRApp appNamed:appName];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *)getAppName:(NSString *)appDisplayName {
|
|
|
|
if ([appDisplayName isEqualToString:DEFAULT_APP_DISPLAY_NAME]) {
|
|
|
|
return DEFAULT_APP_NAME;
|
|
|
|
}
|
|
|
|
return appDisplayName;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *)getAppDisplayName:(NSString *)appName {
|
|
|
|
if ([appName isEqualToString:DEFAULT_APP_NAME]) {
|
|
|
|
return DEFAULT_APP_DISPLAY_NAME;
|
|
|
|
}
|
|
|
|
return appName;
|
|
|
|
}
|
|
|
|
|
2018-02-02 12:05:51 +00:00
|
|
|
+ (void)sendJSEvent:(RCTEventEmitter *)emitter name:(NSString *)name body:(id)body {
|
2017-10-26 10:55:07 +00:00
|
|
|
@try {
|
|
|
|
// TODO: Temporary fix for https://github.com/invertase/react-native-firebase/issues/233
|
|
|
|
// until a better solution comes around
|
|
|
|
if (emitter.bridge) {
|
|
|
|
[emitter sendEventWithName:name body:body];
|
|
|
|
}
|
|
|
|
} @catch (NSException *error) {
|
|
|
|
NSLog(@"An error occurred in sendJSEvent: %@", [error debugDescription]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-02 12:05:51 +00:00
|
|
|
+ (void)sendJSEventWithAppName:(RCTEventEmitter *)emitter app:(FIRApp *)app name:(NSString *)name body:(id)body {
|
2017-10-26 10:55:07 +00:00
|
|
|
// Add the appName to the body
|
|
|
|
NSMutableDictionary *newBody = [body mutableCopy];
|
2018-01-03 20:00:38 +00:00
|
|
|
newBody[@"appName"] = [RNFirebaseUtil getAppDisplayName:app.name];
|
2017-10-26 10:55:07 +00:00
|
|
|
|
|
|
|
[RNFirebaseUtil sendJSEvent:emitter name:name body:newBody];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|