Skip to content

Commit 4570d39

Browse files
author
Dan Walkowski
committed
Merge branch 'master' into fftl-disabler
2 parents 69bd4e2 + 2312d1b commit 4570d39

File tree

14 files changed

+490
-50
lines changed

14 files changed

+490
-50
lines changed

Branch-SDK/Branch-SDK/BNCContentDiscoveryManager.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@
1414
- (NSString *)standardSpotlightIdentifierFromActivity:(NSUserActivity *)userActivity;
1515

1616
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description;
17+
1718
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description callback:(callbackWithUrl)callback;
19+
1820
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable callback:(callbackWithUrl)callback;
21+
1922
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type callback:(callbackWithUrl)callback;
23+
2024
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl callback:(callbackWithUrl)callback;
25+
2126
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords callback:(callbackWithUrl)callback;
27+
2228
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords;
29+
2330
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo;
31+
2432
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable thumbnailUrl:(NSURL *)thumbnailUrl userInfo:(NSDictionary *)userInfo;
33+
2534
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo;
35+
2636
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo callback:(callbackWithUrl)callback;
37+
2738
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback;
2839

2940

41+
42+
/* This one has a different callback, which includes the spotlightIdentifier, and requires a different signature
43+
It cannot be part of the stack of method signatures above, because of the different callback type.*/
44+
- (void)indexContentWithTitle:(NSString *)title description:(NSString *)description publiclyIndexable:(BOOL)publiclyIndexable type:(NSString *)type thumbnailUrl:(NSURL *)thumbnailUrl keywords:(NSSet *)keywords userInfo:(NSDictionary *)userInfo expirationDate:(NSDate *)expirationDate callback:(callbackWithUrl)callback spotlightCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback;
45+
46+
3047
@end

Branch-SDK/Branch-SDK/BNCContentDiscoveryManager.m

Lines changed: 255 additions & 33 deletions
Large diffs are not rendered by default.

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@property (assign, nonatomic) NSInteger retryCount;
3636
@property (assign, nonatomic) NSTimeInterval retryInterval;
3737
@property (assign, nonatomic) NSTimeInterval timeout;
38+
@property (strong, nonatomic) NSString *externalIntentURI;
3839

3940
+ (BNCPreferenceHelper *)preferenceHelper;
4041

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
NSString * const BRANCH_PREFS_KEY_USER_URL = @"bnc_user_url";
3333
NSString * const BRANCH_PREFS_KEY_IS_REFERRABLE = @"bnc_is_referrable";
3434
NSString * const BRANCH_PREFS_KEY_BRANCH_UNIVERSAL_LINK_DOMAINS = @"branch_universal_link_domains";
35+
NSString * const BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI = @"external_intent_uri";
3536

3637
NSString * const BRANCH_PREFS_KEY_CREDITS = @"bnc_credits";
3738
NSString * const BRANCH_PREFS_KEY_CREDIT_BASE = @"bnc_credit_base_";
@@ -51,9 +52,28 @@ @interface BNCPreferenceHelper ()
5152

5253
@implementation BNCPreferenceHelper
5354

54-
@synthesize branchKey = _branchKey, appKey = _appKey, lastRunBranchKey = _lastRunBranchKey, appVersion = _appVersion, deviceFingerprintID = _deviceFingerprintID, sessionID = _sessionID, spotlightIdentifier = _spotlightIdentifier,
55-
identityID = _identityID, linkClickIdentifier = _linkClickIdentifier, userUrl = _userUrl, userIdentity = _userIdentity, sessionParams = _sessionParams, installParams = _installParams, universalLinkUrl = _universalLinkUrl,
56-
isReferrable = _isReferrable, isDebug = _isDebug, isContinuingUserActivity = _isContinuingUserActivity, retryCount = _retryCount, retryInterval = _retryInterval, timeout = _timeout, lastStrongMatchDate = _lastStrongMatchDate;
55+
@synthesize branchKey = _branchKey,
56+
appKey = _appKey,
57+
lastRunBranchKey = _lastRunBranchKey,
58+
appVersion = _appVersion,
59+
deviceFingerprintID = _deviceFingerprintID,
60+
sessionID = _sessionID,
61+
spotlightIdentifier = _spotlightIdentifier,
62+
identityID = _identityID,
63+
linkClickIdentifier = _linkClickIdentifier,
64+
userUrl = _userUrl,
65+
userIdentity = _userIdentity,
66+
sessionParams = _sessionParams,
67+
installParams = _installParams,
68+
universalLinkUrl = _universalLinkUrl,
69+
externalIntentURI = _externalIntentURI,
70+
isReferrable = _isReferrable,
71+
isDebug = _isDebug,
72+
isContinuingUserActivity = _isContinuingUserActivity,
73+
retryCount = _retryCount,
74+
retryInterval = _retryInterval,
75+
timeout = _timeout,
76+
lastStrongMatchDate = _lastStrongMatchDate;
5777

5878
+ (BNCPreferenceHelper *)preferenceHelper {
5979
static BNCPreferenceHelper *preferenceHelper;
@@ -302,6 +322,20 @@ - (void)setSpotlightIdentifier:(NSString *)spotlightIdentifier {
302322
}
303323
}
304324

325+
- (NSString *)externalIntentURI {
326+
if (!_externalIntentURI) {
327+
_externalIntentURI = [self readStringFromDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI];
328+
}
329+
return _externalIntentURI;
330+
}
331+
332+
- (void)setExternalIntentURI:(NSString *)externalIntentURI {
333+
if (![_externalIntentURI isEqualToString:externalIntentURI]) {
334+
_externalIntentURI = externalIntentURI;
335+
[self writeObjectToDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI value:externalIntentURI];
336+
}
337+
}
338+
305339
- (NSString *)universalLinkUrl {
306340
if (!_universalLinkUrl) {
307341
_universalLinkUrl = [self readStringFromDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL];

Branch-SDK/Branch-SDK/Branch.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,15 @@ typedef NS_ENUM(NSUInteger, BranchPromoCodeUsageType) {
401401
*/
402402
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity;
403403

404+
///--------------------------------
405+
/// @name Push Notification Support
406+
///--------------------------------
407+
408+
#pragma mark - Push Notification support
409+
410+
/* Extract the short URL if there is one */
411+
- (void)handlePushNotification:(NSDictionary*) userInfo;
412+
404413
#pragma mark - Deep Link Controller methods
405414

406415
///---------------------------
@@ -458,6 +467,12 @@ typedef NS_ENUM(NSUInteger, BranchPromoCodeUsageType) {
458467
*/
459468
- (void)disableCookieBasedMatching;
460469

470+
/**
471+
If you're using a version of the Facebook SDK that prevents application:didFinishLaunchingWithOptions: from returning
472+
YES/true when a Universal Link is clicked, you should enable this option.
473+
*/
474+
- (void)accountForFacebookSDKPreventingAppLaunch;
475+
461476
#pragma mark - Session Item methods
462477

463478
///--------------------
@@ -1316,6 +1331,22 @@ typedef NS_ENUM(NSUInteger, BranchPromoCodeUsageType) {
13161331
*/
13171332
- (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;
13181333

1334+
/**
1335+
Take the current screen and make it discoverable, adding it to Apple's Core Spotlight index. Will be public if specified. You can override the type as desired, using one of the types provided in MobileCoreServices.
1336+
1337+
@param title Title for the spotlight preview item.
1338+
@param description Description for the spotlight preview item.
1339+
@param thumbnailUrl Url to an image to be used for the thumnbail in spotlight.
1340+
@param linkParams Additional params to be added to the NSUserActivity. These will also be added to the Branch link.
1341+
@param publiclyIndexable Whether or not this item should be added to Apple's public search index.
1342+
@param type The type to use for the NSUserActivity, taken from the list of constants provided in the MobileCoreServices framework.
1343+
@param keywords A set of keywords to be used in Apple's search index.
1344+
@param expirationDate ExpirationDate after which this will not appear in Apple's search index.
1345+
@param callback Callback called with the Branch url this will fallback to.
1346+
@warning These functions are only usable on iOS 9 or above. Earlier versions will simply receive the callback with an error.
1347+
*/
1348+
- (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;
1349+
13191350
#pragma mark - Referral Code methods
13201351

13211352
///-------------------------

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@
5454
NSString * const BRANCH_INIT_KEY_PHONE_NUMBER = @"+phone_number";
5555
NSString * const BRANCH_INIT_KEY_IS_FIRST_SESSION = @"+is_first_session";
5656
NSString * 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

Branch-SDK/Branch-SDK/BranchConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern NSString * const BRANCH_REQUEST_KEY_SCREEN_HEIGHT;
6060
extern NSString * const BRANCH_REQUEST_KEY_DEVICE_NAME;
6161
extern NSString * const BRANCH_REQUEST_KEY_IS_SIMULATOR;
6262
extern NSString * const BRANCH_REQUEST_KEY_LOG;
63+
extern NSString * const BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI;
6364

6465
extern NSString * const BRANCH_REQUEST_ENDPOINT_SET_IDENTITY;
6566
extern NSString * const BRANCH_REQUEST_ENDPOINT_LOGOUT;

Branch-SDK/Branch-SDK/BranchUniversalObject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
3030
@property (nonatomic) ContentIndexMode contentIndexMode;
3131
@property (nonatomic, strong) NSArray *keywords;
3232
@property (nonatomic, strong) NSDate *expirationDate;
33+
@property (nonatomic, strong) NSString *spotlightIdentifier;
3334

3435
- (instancetype)initWithCanonicalIdentifier:(NSString *)canonicalIdentifier;
3536
- (instancetype)initWithTitle:(NSString *)title;
@@ -43,6 +44,7 @@ typedef NS_ENUM(NSInteger, ContentIndexMode) {
4344
- (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties andShareText:(NSString *)shareText fromViewController:(UIViewController *)viewController andCallback:(callback)callback;
4445
- (void)listOnSpotlight;
4546
- (void)listOnSpotlightWithCallback:(callbackWithUrl)callback;
47+
- (void)listOnSpotlightWithIdentifierCallback:(callbackWithUrlAndSpotlightIdentifier)spotlightCallback;
4648

4749
// Convenience method for initSession methods that return BranchUniversalObject, but can be used safely by anyone.
4850
+ (BranchUniversalObject *)getBranchUniversalObjectFromDictionary:(NSDictionary *)dictionary;

0 commit comments

Comments
 (0)