@@ -85,7 +85,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
8585@property (assign , nonatomic ) BOOL useCookieBasedMatching;
8686@property (strong , nonatomic ) NSDictionary *deepLinkDebugParams;
8787@property (assign , nonatomic ) BOOL accountForFacebookSDK;
88-
88+ @property ( assign , nonatomic ) id FBSDKAppLinkUtility;
8989
9090@end
9191
@@ -340,16 +340,20 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)
340340
341341 if ([BNCSystemObserver getOSVersion ].integerValue >= 8 ) {
342342 if (![options objectForKey: UIApplicationLaunchOptionsURLKey] && ![options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
343- [self initUserSessionAndCallCallback: YES ];
343+ // If Facebook SDK is present, call deferred app link check here
344+ if (![self checkFacebookAppLinks ]) {
345+ [self initUserSessionAndCallCallback: YES ];
346+ }
344347 }
345348 else if ([options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
346- self.preferenceHelper .isContinuingUserActivity = YES ;
347349 if (self.accountForFacebookSDK ) {
348350 id activity = [[options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey] objectForKey: @" UIApplicationLaunchOptionsUserActivityKey" ];
349351 if (activity && [activity isKindOfClass: [NSUserActivity class ]]) {
350352 [self continueUserActivity: activity];
353+ return ;
351354 }
352355 }
356+ self.preferenceHelper .shouldWaitForInit = YES ;
353357 }
354358 }
355359 else if (![options objectForKey: UIApplicationLaunchOptionsURLKey]) {
@@ -367,7 +371,7 @@ - (void) setDeepLinkDebugMode:(NSDictionary *)debugParams {
367371
368372- (BOOL )handleDeepLink : (NSURL *)url {
369373 BOOL handled = NO ;
370- if (url) {
374+ if (url && ![url isEqual: [ NSNull null ]] ) {
371375 // always save the incoming url in the preferenceHelper in the externalIntentURI field
372376 self.preferenceHelper .externalIntentURI = [url absoluteString ];
373377
@@ -393,7 +397,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
393397 if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb ]) {
394398 self.preferenceHelper .universalLinkUrl = [userActivity.webpageURL absoluteString ];
395399 [self initUserSessionAndCallCallback: YES ];
396- self.preferenceHelper .isContinuingUserActivity = NO ;
400+ self.preferenceHelper .shouldWaitForInit = NO ;
397401
398402 id branchUniversalLinkDomains = [self .preferenceHelper getBranchUniversalLinkDomains ];
399403 if ([branchUniversalLinkDomains isKindOfClass: [NSString class ]] && [[userActivity.webpageURL absoluteString ] containsString: branchUniversalLinkDomains]) {
@@ -430,7 +434,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
430434 }
431435 }
432436 [self initUserSessionAndCallCallback: YES ];
433- self.preferenceHelper .isContinuingUserActivity = NO ;
437+ self.preferenceHelper .shouldWaitForInit = NO ;
434438
435439 return spotlightIdentifier != nil ;
436440}
@@ -466,6 +470,33 @@ - (void)handlePushNotification:(NSDictionary *) userInfo {
466470 }
467471}
468472
473+ # pragma mark - Facebook App Link check
474+
475+ - (void )registerFacebookDeepLinkingClass : (id )FBSDKAppLinkUtility {
476+ self.FBSDKAppLinkUtility = FBSDKAppLinkUtility;
477+ }
478+
479+ - (BOOL )checkFacebookAppLinks {
480+ if (self.FBSDKAppLinkUtility ) {
481+ SEL fetchDeferredAppLink = NSSelectorFromString (@" fetchDeferredAppLink:" );
482+
483+ if ([self .FBSDKAppLinkUtility methodForSelector: fetchDeferredAppLink]) {
484+ void (^__nullable completionBlock)(NSURL *appLink, NSError *error) = ^void (NSURL *__nullable appLink, NSError *__nullable error) {
485+ self.preferenceHelper .shouldWaitForInit = NO ;
486+ [self handleDeepLink: appLink];
487+ };
488+
489+ self.preferenceHelper .checkedFacebookAppLinks = YES ;
490+ self.preferenceHelper .shouldWaitForInit = YES ;
491+
492+ ((void (*)(id , SEL , void (^ __nullable)(NSURL *__nullable appLink, NSError * __nullable error)))[self .FBSDKAppLinkUtility methodForSelector: fetchDeferredAppLink])(self.FBSDKAppLinkUtility , fetchDeferredAppLink, completionBlock);
493+
494+ return YES ;
495+ }
496+ }
497+
498+ return NO ;
499+ }
469500
470501#pragma mark - Deep Link Controller methods
471502
@@ -1204,7 +1235,7 @@ - (void)registerViewWithParams:(NSDictionary *)params andCallback:(callbackWithP
12041235#pragma mark - Application State Change methods
12051236
12061237- (void )applicationDidBecomeActive {
1207- if (!self.isInitialized && !self.preferenceHelper .isContinuingUserActivity && ![self .requestQueue containsInstallOrOpen ]) {
1238+ if (!self.isInitialized && !self.preferenceHelper .shouldWaitForInit && ![self .requestQueue containsInstallOrOpen ]) {
12081239 [self initUserSessionAndCallCallback: YES ];
12091240 }
12101241}
@@ -1320,7 +1351,7 @@ - (void)processNextQueueItem {
13201351#pragma mark - Session Initialization
13211352
13221353- (void )initSessionIfNeededAndNotInProgress {
1323- if (!self.isInitialized && !self.preferenceHelper .isContinuingUserActivity && ![self .requestQueue containsInstallOrOpen ]) {
1354+ if (!self.isInitialized && !self.preferenceHelper .shouldWaitForInit && ![self .requestQueue containsInstallOrOpen ]) {
13241355 [self initUserSessionAndCallCallback: NO ];
13251356 }
13261357}
0 commit comments