Skip to content

Commit

Permalink
Merge pull request #1139 from BranchMetrics/CORE-2088-backport
Browse files Browse the repository at this point in the history
Prep maintenance release 1.39.4
  • Loading branch information
echo-branch authored Jul 27, 2021
2 parents a8eed23 + 8a9a65b commit e818396
Show file tree
Hide file tree
Showing 25 changed files with 490 additions and 99 deletions.
2 changes: 1 addition & 1 deletion Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
NSString * const BNC_API_BASE_URL = @"https://api2.branch.io";
NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const BNC_SDK_VERSION = @"1.39.3";
NSString * const BNC_SDK_VERSION = @"1.39.4";
30 changes: 30 additions & 0 deletions Branch-SDK/BNCPasteboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// BNCPasteboard.h
// Branch
//
// Created by Ernest Cho on 6/24/21.
// Copyright © 2021 Branch, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface BNCPasteboard : NSObject

/*
Indicates if the client wishes to check for Branch links on install. By default, this is NO.
Set via Branch.checkPasteboardOnInstall
Checked by BranchInstallRequest.makeRequest before checking the pasteboard for a Branch link.
*/
@property (nonatomic, assign) BOOL checkOnInstall;

- (BOOL)isUrlOnPasteboard;
- (nullable NSURL *)checkForBranchLink;

+ (BNCPasteboard *)sharedInstance;

@end

NS_ASSUME_NONNULL_END
56 changes: 56 additions & 0 deletions Branch-SDK/BNCPasteboard.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// BNCPasteboard.m
// Branch
//
// Created by Ernest Cho on 6/24/21.
// Copyright © 2021 Branch, Inc. All rights reserved.
//

#import "BNCPasteboard.h"
#import <UIKit/UIKit.h>
#import "Branch.h"

@implementation BNCPasteboard

+ (BNCPasteboard *)sharedInstance {
static BNCPasteboard *pasteboard;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
pasteboard = [BNCPasteboard new];
});
return pasteboard;
}

- (instancetype)init {
self = [super init];
if (self) {
self.checkOnInstall = NO;
}
return self;
}

- (BOOL)isUrlOnPasteboard {
#if !TARGET_OS_TV
if (@available(iOS 10.0, *)) {
if ([UIPasteboard.generalPasteboard hasURLs]) {
return YES;
}
}
#endif
return NO;
}

- (nullable NSURL *)checkForBranchLink {
if ([self isUrlOnPasteboard]) {
#if !TARGET_OS_TV
// triggers the end user toast message
NSURL *tmp = UIPasteboard.generalPasteboard.URL;
if ([Branch isBranchLink:tmp.absoluteString]) {
return tmp;
}
#endif
}
return nil;
}

@end
1 change: 1 addition & 0 deletions Branch-SDK/BNCPreferenceHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
@property (strong, nonatomic) NSString *linkClickIdentifier;
@property (strong, nonatomic) NSString *spotlightIdentifier;
@property (strong, atomic) NSString *universalLinkUrl;
@property (strong, atomic) NSString *initialReferrer;
@property (strong, nonatomic) NSString *userUrl;
@property (strong, nonatomic) NSString *userIdentity;
@property (strong, nonatomic) NSString *sessionParams;
Expand Down
10 changes: 10 additions & 0 deletions Branch-SDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
static NSString * const BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER = @"bnc_link_click_identifier";
static NSString * const BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER = @"bnc_spotlight_identifier";
static NSString * const BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL = @"bnc_universal_link_url";
static NSString * const BRANCH_PREFS_KEY_INITIAL_REFERRER = @"bnc_initial_referrer";
static NSString * const BRANCH_PREFS_KEY_SESSION_PARAMS = @"bnc_session_params";
static NSString * const BRANCH_PREFS_KEY_INSTALL_PARAMS = @"bnc_install_params";
static NSString * const BRANCH_PREFS_KEY_USER_URL = @"bnc_user_url";
Expand Down Expand Up @@ -75,6 +76,7 @@ @implementation BNCPreferenceHelper
sessionParams = _sessionParams,
installParams = _installParams,
universalLinkUrl = _universalLinkUrl,
initialReferrer = _initialReferrer,
externalIntentURI = _externalIntentURI,
isDebug = _isDebug,
retryCount = _retryCount,
Expand Down Expand Up @@ -315,6 +317,13 @@ - (void)setUniversalLinkUrl:(NSString *)universalLinkUrl {
[self writeObjectToDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL value:universalLinkUrl];
}

- (NSString *)initialReferrer {
return [self readStringFromDefaults:BRANCH_REQUEST_KEY_INITIAL_REFERRER];
}

- (void)setInitialReferrer:(NSString *)initialReferrer {
[self writeObjectToDefaults:BRANCH_REQUEST_KEY_INITIAL_REFERRER value:initialReferrer];
}
- (NSString *)sessionParams {
@synchronized (self) {
if (!_sessionParams) {
Expand Down Expand Up @@ -659,6 +668,7 @@ - (void) clearTrackingInformation {
self.spotlightIdentifier = nil;
self.referringURL = nil;
self.universalLinkUrl = nil;
self.initialReferrer = nil;
self.installParams = nil;
self.appleSearchAdDetails = nil;
self.appleSearchAdNeedsSend = NO;
Expand Down
27 changes: 27 additions & 0 deletions Branch-SDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,24 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
*/
- (void)ignoreAppleSearchAdsTestData;

/**
Checks the pasteboard (clipboard) for a Branch Link on App Install.
If found, the Branch Link is used to provide deferred deeplink data.
Note, this may display a toast message to the end user.
*/
- (void)checkPasteboardOnInstall;

/**
Let's client know if the Branch SDK will trigger a pasteboard toast to the end user.
All of the following conditions must be true.
1. Developer called checkPastboardOnInstall before initSession
2. A URL is on the pasteboard
3. First time app is run with Branch SDK
*/
- (BOOL)willShowPasteboardToast;

/**
Set the AppGroup used to share data between the App Clip and the Full App.
Expand Down Expand Up @@ -774,6 +792,15 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
*/
- (void)registerPluginName:(NSString *)name version:(NSString *)version;

/**
Checks if a url string is a probable Branch link.
Checks against the Info.plist and the standard Branch list.
@param urlString URL as an NSString
*/
+ (BOOL)isBranchLink:(NSString *)urlString;

/**
Key-value pairs to be included in the metadata on every request.
Expand Down
66 changes: 37 additions & 29 deletions Branch-SDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#import "BNCAppGroupsData.h"
#import "BNCPartnerParameters.h"
#import "BranchEvent.h"
#import "BNCPasteboard.h"

#if !TARGET_OS_TV
#import "BNCUserAgentCollector.h"
Expand Down Expand Up @@ -225,6 +226,10 @@ - (id)initWithInterface:(BNCServerInterface *)interface

BranchJsonConfig *config = BranchJsonConfig.instance;

if (config.checkPasteboardOnInstall) {
[self checkPasteboardOnInstall];
}

if (config.delayInitToCheckForSearchAds) {
[self delayInitToCheckForSearchAds];
}
Expand Down Expand Up @@ -800,26 +805,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS

[self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier];

id branchUniversalLinkDomains = [self.preferenceHelper getBranchUniversalLinkDomains];
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] && [urlString bnc_containsString:branchUniversalLinkDomains]) {
return YES;
} else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
for (id oneDomain in branchUniversalLinkDomains) {
if ([oneDomain isKindOfClass:[NSString class]] && [urlString bnc_containsString:oneDomain]) {
return YES;
}
}
}

NSString *userActivityURL = urlString;
NSArray *branchDomains = [NSArray arrayWithObjects:@"bnc.lt", @"app.link", @"test-app.link", nil];
for (NSString* domain in branchDomains) {
if ([userActivityURL bnc_containsString:domain]) {
return YES;
}
}

return NO;
return [Branch isBranchLink:urlString];
}

- (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
Expand All @@ -829,6 +815,12 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSString *)sceneIdentifier {
BNCLogDebugSDK(@"continueUserActivity:");

if (@available(iOS 11.0, *)) {
if (userActivity.referrerURL) {
self.preferenceHelper.initialReferrer = userActivity.referrerURL.absoluteString;
}
}

// Check to see if a browser activity needs to be handled
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
return [self handleDeepLink:userActivity.webpageURL sceneIdentifier:sceneIdentifier];
Expand All @@ -841,9 +833,9 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS
spotlightIdentifier = [self.contentDiscoveryManager spotlightIdentifierFromActivity:userActivity];
NSURL *webURL = userActivity.webpageURL;

if ([self isBranchLink:userActivity.userInfo[CSSearchableItemActivityIdentifier]]) {
if ([Branch isBranchLink:userActivity.userInfo[CSSearchableItemActivityIdentifier]]) {
return [self handleDeepLink:[NSURL URLWithString:userActivity.userInfo[CSSearchableItemActivityIdentifier]] sceneIdentifier:sceneIdentifier];
} else if (webURL != nil && [self isBranchLink:[webURL absoluteString]]) {
} else if (webURL != nil && [Branch isBranchLink:[webURL absoluteString]]) {
return [self handleDeepLink:webURL sceneIdentifier:sceneIdentifier];
} else if (spotlightIdentifier) {
self.preferenceHelper.spotlightIdentifier = spotlightIdentifier;
Expand All @@ -860,25 +852,28 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS
return spotlightIdentifier != nil;
}

- (BOOL)isBranchLink:(NSString*)urlString {
id branchUniversalLinkDomains = [self.preferenceHelper getBranchUniversalLinkDomains];
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] &&
[urlString containsString:branchUniversalLinkDomains]) {
// checks if URL string looks like a branch link
+ (BOOL)isBranchLink:(NSString *)urlString {
id branchUniversalLinkDomains = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"branch_universal_link_domains"];

// check url list in bundle
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] && [urlString containsString:branchUniversalLinkDomains]) {
return YES;
}
else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
} else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
for (id oneDomain in branchUniversalLinkDomains) {
if ([oneDomain isKindOfClass:[NSString class]] && [urlString containsString:oneDomain]) {
return YES;
}
}
}

// check default urls
NSString *userActivityURL = urlString;
NSArray *branchDomains = [NSArray arrayWithObjects:@"bnc.lt", @"app.link", @"test-app.link", nil];
for (NSString* domain in branchDomains) {
if ([userActivityURL containsString:domain])
if ([userActivityURL containsString:domain]) {
return YES;
}
}
return NO;
}
Expand Down Expand Up @@ -950,6 +945,19 @@ - (void)ignoreAppleSearchAdsTestData {
#endif
}

- (void)checkPasteboardOnInstall {
[BNCPasteboard sharedInstance].checkOnInstall = YES;
}

- (BOOL)willShowPasteboardToast {
if (!self.preferenceHelper.identityID &&
[BNCPasteboard sharedInstance].checkOnInstall &&
[BNCPasteboard sharedInstance].isUrlOnPasteboard) {
return YES;
}
return NO;
}

- (void)checkAppleSearchAdsAttribution {
#if !TARGET_OS_TV
if (![BNCAppleSearchAds sharedInstance].enableAppleSearchAdsCheck) {
Expand Down
2 changes: 2 additions & 0 deletions Branch-SDK/BranchConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extern NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION;
extern NSString * const BRANCH_REQUEST_KEY_LINK_IDENTIFIER;
extern NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER;
extern NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL;
extern NSString * const BRANCH_REQUEST_KEY_LOCAL_URL;
extern NSString * const BRANCH_REQUEST_KEY_INITIAL_REFERRER;
extern NSString * const BRANCH_REQUEST_KEY_BRAND;
extern NSString * const BRANCH_REQUEST_KEY_MODEL;
extern NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH;
Expand Down
2 changes: 2 additions & 0 deletions Branch-SDK/BranchConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION = @"apple_ad_attribution_checked";
NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER = @"spotlight_identifier";
NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL = @"universal_link_url";
NSString * const BRANCH_REQUEST_KEY_LOCAL_URL = @"local_url";
NSString * const BRANCH_REQUEST_KEY_INITIAL_REFERRER = @"initial_referrer";
NSString * const BRANCH_REQUEST_KEY_BRAND = @"brand";
NSString * const BRANCH_REQUEST_KEY_MODEL = @"model";
NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH = @"screen_width";
Expand Down
10 changes: 9 additions & 1 deletion Branch-SDK/BranchInstallRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#import "BNCAppleReceipt.h"
#import "BNCAppGroupsData.h"
#import "BNCPartnerParameters.h"
#import "BNCPasteboard.h"

@implementation BranchInstallRequest

Expand All @@ -37,7 +38,7 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
[self safeSetValue:preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:params];
[self safeSetValue:preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:params];
[self safeSetValue:preferenceHelper.universalLinkUrl forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:params];

[self safeSetValue:preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:params];
[self safeSetValue:[[BNCAppleReceipt sharedInstance] installReceipt] forKey:BRANCH_REQUEST_KEY_APPLE_RECEIPT onDict:params];
[self safeSetValue:[NSNumber numberWithBool:[[BNCAppleReceipt sharedInstance] isTestFlight]] forKey:BRANCH_REQUEST_KEY_APPLE_TESTFLIGHT onDict:params];

Expand Down Expand Up @@ -67,6 +68,13 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
onDict:params];
}

if ([BNCPasteboard sharedInstance].checkOnInstall) {
NSURL *pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
if (pasteboardURL) {
[self safeSetValue:pasteboardURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:params];
}
}

NSString *appleAttributionToken = [BNCSystemObserver appleAttributionToken];
if (appleAttributionToken) {
preferenceHelper.appleAttributionTokenChecked = YES;
Expand Down
2 changes: 2 additions & 0 deletions Branch-SDK/BranchJsonConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern NSString * _Nonnull const BranchJsonConfigDelayInitToCheckForSearchAdsOpt
extern NSString * _Nonnull const BranchJsonConfigAppleSearchAdsDebugModeOption;
extern NSString * _Nonnull const BranchJsonConfigDeferInitializationForJSLoadOption;
extern NSString * _Nonnull const BranchJsonConfigEnableFacebookLinkCheck;
extern NSString * _Nonnull const BranchJsonConfigCheckPasteboardOnInstall;

@interface BranchJsonConfig : NSObject

Expand All @@ -31,6 +32,7 @@ extern NSString * _Nonnull const BranchJsonConfigEnableFacebookLinkCheck;
@property (nonatomic, readonly) BOOL appleSearchAdsDebugMode;
@property (nonatomic, readonly) BOOL deferInitializationForJSLoad;
@property (nonatomic, readonly) BOOL enableFacebookLinkCheck;
@property (nonatomic, readonly) BOOL checkPasteboardOnInstall;

- (nullable id)objectForKey:(NSString * _Nonnull)key;
- (nullable id)objectForKeyedSubscript:(NSString * _Nonnull)key;
Expand Down
7 changes: 7 additions & 0 deletions Branch-SDK/BranchJsonConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
NSString * _Nonnull const BranchJsonConfigAppleSearchAdsDebugModeOption = @"appleSearchAdsDebugMode";
NSString * _Nonnull const BranchJsonConfigDeferInitializationForJSLoadOption = @"deferInitializationForJSLoad";
NSString * _Nonnull const BranchJsonConfigEnableFacebookLinkCheck = @"enableFacebookLinkCheck";
NSString * _Nonnull const BranchJsonConfigCheckPasteboardOnInstall = @"checkPasteboardOnInstall";

@interface BranchJsonConfig()
@property (nonatomic) NSDictionary *configuration;
Expand Down Expand Up @@ -148,6 +149,12 @@ - (BOOL)enableFacebookLinkCheck
return number.boolValue;
}

- (BOOL)checkPasteboardOnInstall
{
NSNumber *number = self[BranchJsonConfigCheckPasteboardOnInstall];
return number.boolValue;
}

- (NSString *)branchKey
{
return self[BranchJsonConfigBranchKeyOption];
Expand Down
Loading

0 comments on commit e818396

Please sign in to comment.