5454NSString * const BRANCH_INIT_KEY_PHONE_NUMBER = @" +phone_number" ;
5555NSString * const BRANCH_INIT_KEY_IS_FIRST_SESSION = @" +is_first_session" ;
5656NSString * const BRANCH_INIT_KEY_CLICKED_BRANCH_LINK = @" +clicked_branch_link" ;
57+ NSString * const BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY = @" branch" ;
5758
5859@interface Branch () <BranchDeepLinkingControllerCompletionDelegate>
5960
60- @property (strong , nonatomic ) BNCServerInterface *bServerInterface;
6161
62+ @property (strong , nonatomic ) BNCServerInterface *bServerInterface;
6263@property (strong , nonatomic ) NSTimer *sessionTimer;
6364@property (strong , nonatomic ) BNCServerRequestQueue *requestQueue;
6465@property (strong , nonatomic ) dispatch_semaphore_t processing_sema;
@@ -77,6 +78,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate>
7778@property (strong , nonatomic ) NSMutableDictionary *deepLinkControllers;
7879@property (weak , nonatomic ) UIViewController *deepLinkPresentingController;
7980@property (assign , nonatomic ) BOOL useCookieBasedMatching;
81+ @property (assign , nonatomic ) BOOL accountForFacebookSDK;
8082
8183@end
8284
@@ -251,6 +253,10 @@ - (void)disableCookieBasedMatching {
251253 self.useCookieBasedMatching = NO ;
252254}
253255
256+ - (void )accountForFacebookSDKPreventingAppLaunch {
257+ self.accountForFacebookSDK = YES ;
258+ }
259+
254260#pragma mark - InitSession Permutation methods
255261
256262- (void )initSession {
@@ -334,30 +340,46 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)
334340 [self initSessionWithLaunchOptions: options isReferrable: isReferrable explicitlyRequestedReferrable: explicitlyRequestedReferrable automaticallyDisplayController: automaticallyDisplayController];
335341}
336342
343+
337344- (void )initSessionWithLaunchOptions : (NSDictionary *)options isReferrable : (BOOL )isReferrable explicitlyRequestedReferrable : (BOOL )explicitlyRequestedReferrable automaticallyDisplayController : (BOOL )automaticallyDisplayController {
338345 self.shouldAutomaticallyDeepLink = automaticallyDisplayController;
339346
340347 self.preferenceHelper .isReferrable = isReferrable;
341348 self.preferenceHelper .explicitlyRequestedReferrable = explicitlyRequestedReferrable;
349+
350+ // Handle push notification on app launch
351+ if ([options objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey]) {
352+ id branchUrlFromPush = [options objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY];
353+ if ([branchUrlFromPush isKindOfClass: [NSString class ]]) {
354+ self.preferenceHelper .universalLinkUrl = branchUrlFromPush;
355+ }
356+ }
342357
343358 if ([BNCSystemObserver getOSVersion ].integerValue >= 8 ) {
344359 if (![options objectForKey: UIApplicationLaunchOptionsURLKey] && ![options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
345360 [self initUserSessionAndCallCallback: YES ];
346361 }
347362 else if ([options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
348363 self.preferenceHelper .isContinuingUserActivity = YES ;
364+ if (self.accountForFacebookSDK ) {
365+ id activity = [[options objectForKey: UIApplicationLaunchOptionsUserActivityDictionaryKey] objectForKey: @" UIApplicationLaunchOptionsUserActivityKey" ];
366+ if (activity && [activity isKindOfClass: [NSUserActivity class ]]) {
367+ [self continueUserActivity: activity];
368+ }
369+ }
349370 }
350371 }
351- else {
352- if (![options objectForKey: UIApplicationLaunchOptionsURLKey]) {
353- [self initUserSessionAndCallCallback: YES ];
354- }
372+ else if (![options objectForKey: UIApplicationLaunchOptionsURLKey]) {
373+ [self initUserSessionAndCallCallback: YES ];
355374 }
356375}
357376
358377- (BOOL )handleDeepLink : (NSURL *)url {
359378 BOOL handled = NO ;
360379 if (url) {
380+ // always save the incoming url in the preferenceHelper in the externalIntentURI field
381+ self.preferenceHelper .externalIntentURI = [url absoluteString ];
382+
361383 NSString *query = [url fragment ];
362384 if (!query) {
363385 query = [url query ];
@@ -376,6 +398,7 @@ - (BOOL)handleDeepLink:(NSURL *)url {
376398}
377399
378400- (BOOL )continueUserActivity : (NSUserActivity *)userActivity {
401+ // check to see if a browser activity needs to be handled
379402 if ([userActivity.activityType isEqualToString: NSUserActivityTypeBrowsingWeb ]) {
380403 self.preferenceHelper .universalLinkUrl = [userActivity.webpageURL absoluteString ];
381404
@@ -397,6 +420,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
397420 return [[userActivity.webpageURL absoluteString ] containsString: @" bnc.lt" ];
398421 }
399422
423+ // check to see if a spotlight activity needs to be handled
400424 NSString *spotlightIdentifier = [self .contentDiscoveryManager spotlightIdentifierFromActivity: userActivity];
401425
402426 if (spotlightIdentifier) {
@@ -415,6 +439,29 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
415439}
416440
417441
442+ #pragma mark - Push Notification support
443+
444+ // handle push notification if app is already launched
445+ - (void )handlePushNotification : (NSDictionary *) userInfo {
446+ // If app is active, then close out the session and start a new one
447+ if ([[UIApplication sharedApplication ] applicationState ] == UIApplicationStateActive) {
448+ [self callClose ];
449+ }
450+
451+ // look for a branch shortlink in the payload (shortlink because iOS7 only supports 256 bytes)
452+ NSString *urlStr = [userInfo objectForKey: BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY];
453+ if (urlStr) {
454+ // reusing this field, so as not to create yet another url slot on prefshelper
455+ self.preferenceHelper .universalLinkUrl = urlStr;
456+ }
457+
458+ // Again, if app is active, then close out the session and start a new one
459+ if ([[UIApplication sharedApplication ] applicationState ] == UIApplicationStateActive) {
460+ [self applicationDidBecomeActive ];
461+ }
462+ }
463+
464+
418465#pragma mark - Deep Link Controller methods
419466
420467- (void )registerDeepLinkController : (UIViewController <BranchDeepLinkingController> *)controller forKey : (NSString *)key {
@@ -838,11 +885,14 @@ - (void)createDiscoverableContentWithTitle:(NSString *)title description:(NSStri
838885- (void )createDiscoverableContentWithTitle : (NSString *)title description : (NSString *)description thumbnailUrl : (NSURL *)thumbnailUrl linkParams : (NSDictionary *)linkParams type : (NSString *)type publiclyIndexable : (BOOL )publiclyIndexable keywords : (NSSet *)keywords callback : (callbackWithUrl)callback {
839886 [self .contentDiscoveryManager indexContentWithTitle: title description: description publiclyIndexable: publiclyIndexable type: type thumbnailUrl: thumbnailUrl keywords: keywords userInfo: linkParams callback: callback];
840887}
841-
842888- (void )createDiscoverableContentWithTitle : (NSString *)title description : (NSString *)description thumbnailUrl : (NSURL *)thumbnailUrl linkParams : (NSDictionary *)linkParams type : (NSString *)type publiclyIndexable : (BOOL )publiclyIndexable keywords : (NSSet *)keywords expirationDate : (NSDate *)expirationDate callback : (callbackWithUrl)callback {
843889 [self .contentDiscoveryManager indexContentWithTitle: title description: description publiclyIndexable: publiclyIndexable type: type thumbnailUrl: thumbnailUrl keywords: keywords userInfo: linkParams expirationDate: expirationDate callback: callback];
844890}
845891
892+ // Use this with iOS 9+ only
893+ - (void )createDiscoverableContentWithTitle : (NSString *)title description : (NSString *)description thumbnailUrl : (NSURL *)thumbnailUrl linkParams : (NSDictionary *)linkParams type : (NSString *)type publiclyIndexable : (BOOL )publiclyIndexable keywords : (NSSet *)keywords expirationDate : (NSDate *)expirationDate spotlightCallback : (callbackWithUrlAndSpotlightIdentifier)spotlightCallback {
894+ [self .contentDiscoveryManager indexContentWithTitle: title description: description publiclyIndexable: publiclyIndexable type: type thumbnailUrl: thumbnailUrl keywords: keywords userInfo: linkParams expirationDate: expirationDate callback: nil spotlightCallback: spotlightCallback];
895+ }
846896
847897#pragma mark - Referral methods
848898
0 commit comments