Skip to content

Commit

Permalink
Merge pull request #202 from ostdotcom/master
Browse files Browse the repository at this point in the history
deep linking fix.
  • Loading branch information
akshayraje authored Feb 10, 2020
2 parents 669daba + 9194304 commit fbfaba1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
60 changes: 56 additions & 4 deletions ios/Pepo2/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -104,11 +114,22 @@ - (void) setupTrustKit {
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)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;
Expand All @@ -118,7 +139,6 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction
return YES;
}


- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
Expand All @@ -128,21 +148,53 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
#endif
}

-(BOOL) isWhiteListedUrl:(NSURL *) url {
// Get whitelisted Pepo Domains
NSArray<NSString *> *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<id<UIUserActivityRestoring>> * _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;

}
Expand Down
4 changes: 3 additions & 1 deletion src/constants/AppConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ const AppConfig = {
failed: 'FAILED',
not_started: 'NOT_STARTED',
in_progress: 'IN_PROGRESS'
}
},

remoteConfigCacheTimeout: 3600

};

Expand Down
3 changes: 2 additions & 1 deletion src/services/RemoteConfig.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fbfaba1

Please sign in to comment.