diff --git a/ios/Pepo2/AppDelegate.m b/ios/Pepo2/AppDelegate.m index 21a903de..aadaed04 100644 --- a/ios/Pepo2/AppDelegate.m +++ b/ios/Pepo2/AppDelegate.m @@ -26,6 +26,16 @@ //static NSString *const CUSTOM_URL_SCHEME = @"com.pepo.v2.production"; @implementation AppDelegate + ++ (NSArray *)getPepoDomains +{ + static NSArray *_domains; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _domains = @[@"https://stagingpepo.com/", @"https://pepo.com/", @"https://sandboxpepo.com/"]; + }); + return _domains; +} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { @@ -104,11 +114,22 @@ - (void) setupTrustKit { - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { BOOL handled; + // Firebase consume valid links and throw errors, hence first handle the whitelisted domains + // And then let Firebase do it job. + if ([self isWhiteListedUrl:url]) { + handled = [RCTLinkingManager application:app openURL:url options:options]; + if (handled) { + return handled; + } + } + + // If we are not able to handle whitelisted domains, let firebase handle it here handled = [[RNFirebaseLinks instance] application:app openURL:url options:options]; if (handled) { return handled; } + // If links are neither whitelsted nor handled by Firebase, fallback handled = [RCTLinkingManager application:app openURL:url options:options]; if (handled) { return handled; @@ -118,7 +139,6 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction return YES; } - - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG @@ -128,21 +148,53 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge #endif } +-(BOOL) isWhiteListedUrl:(NSURL *) url { + // Get whitelisted Pepo Domains + NSArray *domains = [[self class] getPepoDomains]; + + // Check if domain is whitelisted or not + BOOL isWhiteListedDomain = false; + for (NSString *domain in domains) { + if ([[url absoluteString] hasPrefix:domain]) { + isWhiteListedDomain = true; + continue; + } + } + + return isWhiteListedDomain; +} + - (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray> * _Nullable))restorationHandler { - BOOL handled = [[RNFirebaseLinks instance] application:application + + // Get the URL from userActivity + NSURL *url = userActivity.webpageURL; + + // Firebase consume valid links and throw errors, hence first handle the whitelisted domains + // And then let Firebase do it job. + BOOL handled = NO; + if ([self isWhiteListedUrl:url]) { + handled = [RCTLinkingManager application:application + continueUserActivity:userActivity + restorationHandler:restorationHandler]; + if ( handled ) { + return handled; + } + } + + // If we are not able to handle whitelisted domains, let firebase handle it here + handled = [[RNFirebaseLinks instance] application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; - if ( handled ) { return handled; } + // If links are neither whitelsted nor handled by Firebase, fallback handled = [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; - return handled; } diff --git a/src/constants/AppConfig.js b/src/constants/AppConfig.js index 3e332bc5..2c26d067 100644 --- a/src/constants/AppConfig.js +++ b/src/constants/AppConfig.js @@ -464,7 +464,9 @@ const AppConfig = { failed: 'FAILED', not_started: 'NOT_STARTED', in_progress: 'IN_PROGRESS' - } + }, + + remoteConfigCacheTimeout: 3600 }; diff --git a/src/services/RemoteConfig.js b/src/services/RemoteConfig.js index 4e7d389a..30ac2f88 100644 --- a/src/services/RemoteConfig.js +++ b/src/services/RemoteConfig.js @@ -1,6 +1,7 @@ import firebase from 'react-native-firebase'; import assignIn from "lodash/assignIn"; import DefaultConstants from '../constants/RemoteConfigDefaults'; +import appConfig from '../constants/AppConfig'; class RemoteConfig { @@ -32,7 +33,7 @@ class RemoteConfig { } firebaseConfigFetch(){ - firebase.config().fetch() + firebase.config().fetch(appConfig.remoteConfigCacheTimeout) .then(() => { console.log('Activating remote fetched data...'); return firebase.config().activateFetched();