Skip to content

Commit b1a66b4

Browse files
committed
[release] 1.39.4
1 parent e9d72d8 commit b1a66b4

26 files changed

+492
-122
lines changed

Branch-SDK/BNCConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
NSString * const BNC_API_BASE_URL = @"https://api2.branch.io";
1212
NSString * const BNC_API_VERSION = @"v1";
1313
NSString * const BNC_LINK_URL = @"https://bnc.lt";
14-
NSString * const BNC_SDK_VERSION = @"1.39.3";
14+
NSString * const BNC_SDK_VERSION = @"1.39.4";

Branch-SDK/BNCPasteboard.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// BNCPasteboard.h
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 6/24/21.
6+
// Copyright © 2021 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface BNCPasteboard : NSObject
14+
15+
/*
16+
Indicates if the client wishes to check for Branch links on install. By default, this is NO.
17+
18+
Set via Branch.checkPasteboardOnInstall
19+
Checked by BranchInstallRequest.makeRequest before checking the pasteboard for a Branch link.
20+
*/
21+
@property (nonatomic, assign) BOOL checkOnInstall;
22+
23+
- (BOOL)isUrlOnPasteboard;
24+
- (nullable NSURL *)checkForBranchLink;
25+
26+
+ (BNCPasteboard *)sharedInstance;
27+
28+
@end
29+
30+
NS_ASSUME_NONNULL_END

Branch-SDK/BNCPasteboard.m

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// BNCPasteboard.m
3+
// Branch
4+
//
5+
// Created by Ernest Cho on 6/24/21.
6+
// Copyright © 2021 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import "BNCPasteboard.h"
10+
#import <UIKit/UIKit.h>
11+
#import "Branch.h"
12+
13+
@implementation BNCPasteboard
14+
15+
+ (BNCPasteboard *)sharedInstance {
16+
static BNCPasteboard *pasteboard;
17+
static dispatch_once_t onceToken;
18+
dispatch_once(&onceToken, ^{
19+
pasteboard = [BNCPasteboard new];
20+
});
21+
return pasteboard;
22+
}
23+
24+
- (instancetype)init {
25+
self = [super init];
26+
if (self) {
27+
self.checkOnInstall = NO;
28+
}
29+
return self;
30+
}
31+
32+
- (BOOL)isUrlOnPasteboard {
33+
#if !TARGET_OS_TV
34+
if (@available(iOS 10.0, *)) {
35+
if ([UIPasteboard.generalPasteboard hasURLs]) {
36+
return YES;
37+
}
38+
}
39+
#endif
40+
return NO;
41+
}
42+
43+
- (nullable NSURL *)checkForBranchLink {
44+
if ([self isUrlOnPasteboard]) {
45+
#if !TARGET_OS_TV
46+
// triggers the end user toast message
47+
NSURL *tmp = UIPasteboard.generalPasteboard.URL;
48+
if ([Branch isBranchLink:tmp.absoluteString]) {
49+
return tmp;
50+
}
51+
#endif
52+
}
53+
return nil;
54+
}
55+
56+
@end

Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void);
2828
@property (strong, nonatomic) NSString *linkClickIdentifier;
2929
@property (strong, nonatomic) NSString *spotlightIdentifier;
3030
@property (strong, atomic) NSString *universalLinkUrl;
31+
@property (strong, atomic) NSString *initialReferrer;
3132
@property (strong, nonatomic) NSString *userUrl;
3233
@property (strong, nonatomic) NSString *userIdentity;
3334
@property (strong, nonatomic) NSString *sessionParams;

Branch-SDK/BNCPreferenceHelper.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
static NSString * const BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER = @"bnc_link_click_identifier";
3434
static NSString * const BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER = @"bnc_spotlight_identifier";
3535
static NSString * const BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL = @"bnc_universal_link_url";
36+
static NSString * const BRANCH_PREFS_KEY_INITIAL_REFERRER = @"bnc_initial_referrer";
3637
static NSString * const BRANCH_PREFS_KEY_SESSION_PARAMS = @"bnc_session_params";
3738
static NSString * const BRANCH_PREFS_KEY_INSTALL_PARAMS = @"bnc_install_params";
3839
static NSString * const BRANCH_PREFS_KEY_USER_URL = @"bnc_user_url";
@@ -75,6 +76,7 @@ @implementation BNCPreferenceHelper
7576
sessionParams = _sessionParams,
7677
installParams = _installParams,
7778
universalLinkUrl = _universalLinkUrl,
79+
initialReferrer = _initialReferrer,
7880
externalIntentURI = _externalIntentURI,
7981
isDebug = _isDebug,
8082
retryCount = _retryCount,
@@ -315,6 +317,13 @@ - (void)setUniversalLinkUrl:(NSString *)universalLinkUrl {
315317
[self writeObjectToDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL value:universalLinkUrl];
316318
}
317319

320+
- (NSString *)initialReferrer {
321+
return [self readStringFromDefaults:BRANCH_REQUEST_KEY_INITIAL_REFERRER];
322+
}
323+
324+
- (void)setInitialReferrer:(NSString *)initialReferrer {
325+
[self writeObjectToDefaults:BRANCH_REQUEST_KEY_INITIAL_REFERRER value:initialReferrer];
326+
}
318327
- (NSString *)sessionParams {
319328
@synchronized (self) {
320329
if (!_sessionParams) {
@@ -659,6 +668,7 @@ - (void) clearTrackingInformation {
659668
self.spotlightIdentifier = nil;
660669
self.referringURL = nil;
661670
self.universalLinkUrl = nil;
671+
self.initialReferrer = nil;
662672
self.installParams = nil;
663673
self.appleSearchAdDetails = nil;
664674
self.appleSearchAdNeedsSend = NO;

Branch-SDK/Branch.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,24 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
676676
*/
677677
- (void)ignoreAppleSearchAdsTestData;
678678

679+
/**
680+
Checks the pasteboard (clipboard) for a Branch Link on App Install.
681+
If found, the Branch Link is used to provide deferred deeplink data.
682+
683+
Note, this may display a toast message to the end user.
684+
*/
685+
- (void)checkPasteboardOnInstall;
686+
687+
/**
688+
Let's client know if the Branch SDK will trigger a pasteboard toast to the end user.
689+
All of the following conditions must be true.
690+
691+
1. Developer called checkPastboardOnInstall before initSession
692+
2. A URL is on the pasteboard
693+
3. First time app is run with Branch SDK
694+
*/
695+
- (BOOL)willShowPasteboardToast;
696+
679697
/**
680698
Set the AppGroup used to share data between the App Clip and the Full App.
681699
@@ -774,6 +792,15 @@ typedef NS_ENUM(NSUInteger, BranchCreditHistoryOrder) {
774792
*/
775793
- (void)registerPluginName:(NSString *)name version:(NSString *)version;
776794

795+
/**
796+
Checks if a url string is a probable Branch link.
797+
798+
Checks against the Info.plist and the standard Branch list.
799+
800+
@param urlString URL as an NSString
801+
*/
802+
+ (BOOL)isBranchLink:(NSString *)urlString;
803+
777804
/**
778805
Key-value pairs to be included in the metadata on every request.
779806

Branch-SDK/Branch.m

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#import "BNCAppGroupsData.h"
4646
#import "BNCPartnerParameters.h"
4747
#import "BranchEvent.h"
48+
#import "BNCPasteboard.h"
4849

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

226227
BranchJsonConfig *config = BranchJsonConfig.instance;
227228

229+
if (config.checkPasteboardOnInstall) {
230+
[self checkPasteboardOnInstall];
231+
}
232+
228233
if (config.delayInitToCheckForSearchAds) {
229234
[self delayInitToCheckForSearchAds];
230235
}
@@ -800,26 +805,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS
800805

801806
[self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier];
802807

803-
id branchUniversalLinkDomains = [self.preferenceHelper getBranchUniversalLinkDomains];
804-
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] && [urlString bnc_containsString:branchUniversalLinkDomains]) {
805-
return YES;
806-
} else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
807-
for (id oneDomain in branchUniversalLinkDomains) {
808-
if ([oneDomain isKindOfClass:[NSString class]] && [urlString bnc_containsString:oneDomain]) {
809-
return YES;
810-
}
811-
}
812-
}
813-
814-
NSString *userActivityURL = urlString;
815-
NSArray *branchDomains = [NSArray arrayWithObjects:@"bnc.lt", @"app.link", @"test-app.link", nil];
816-
for (NSString* domain in branchDomains) {
817-
if ([userActivityURL bnc_containsString:domain]) {
818-
return YES;
819-
}
820-
}
821-
822-
return NO;
808+
return [Branch isBranchLink:urlString];
823809
}
824810

825811
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
@@ -829,6 +815,12 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
829815
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSString *)sceneIdentifier {
830816
BNCLogDebugSDK(@"continueUserActivity:");
831817

818+
if (@available(iOS 11.0, tvOS 11.0, *)) {
819+
if (userActivity.referrerURL) {
820+
self.preferenceHelper.initialReferrer = userActivity.referrerURL.absoluteString;
821+
}
822+
}
823+
832824
// Check to see if a browser activity needs to be handled
833825
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
834826
return [self handleDeepLink:userActivity.webpageURL sceneIdentifier:sceneIdentifier];
@@ -841,9 +833,9 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS
841833
spotlightIdentifier = [self.contentDiscoveryManager spotlightIdentifierFromActivity:userActivity];
842834
NSURL *webURL = userActivity.webpageURL;
843835

844-
if ([self isBranchLink:userActivity.userInfo[CSSearchableItemActivityIdentifier]]) {
836+
if ([Branch isBranchLink:userActivity.userInfo[CSSearchableItemActivityIdentifier]]) {
845837
return [self handleDeepLink:[NSURL URLWithString:userActivity.userInfo[CSSearchableItemActivityIdentifier]] sceneIdentifier:sceneIdentifier];
846-
} else if (webURL != nil && [self isBranchLink:[webURL absoluteString]]) {
838+
} else if (webURL != nil && [Branch isBranchLink:[webURL absoluteString]]) {
847839
return [self handleDeepLink:webURL sceneIdentifier:sceneIdentifier];
848840
} else if (spotlightIdentifier) {
849841
self.preferenceHelper.spotlightIdentifier = spotlightIdentifier;
@@ -860,25 +852,28 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS
860852
return spotlightIdentifier != nil;
861853
}
862854

863-
- (BOOL)isBranchLink:(NSString*)urlString {
864-
id branchUniversalLinkDomains = [self.preferenceHelper getBranchUniversalLinkDomains];
865-
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] &&
866-
[urlString containsString:branchUniversalLinkDomains]) {
855+
// checks if URL string looks like a branch link
856+
+ (BOOL)isBranchLink:(NSString *)urlString {
857+
id branchUniversalLinkDomains = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"branch_universal_link_domains"];
858+
859+
// check url list in bundle
860+
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] && [urlString containsString:branchUniversalLinkDomains]) {
867861
return YES;
868-
}
869-
else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
862+
} else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
870863
for (id oneDomain in branchUniversalLinkDomains) {
871864
if ([oneDomain isKindOfClass:[NSString class]] && [urlString containsString:oneDomain]) {
872865
return YES;
873866
}
874867
}
875868
}
876869

870+
// check default urls
877871
NSString *userActivityURL = urlString;
878872
NSArray *branchDomains = [NSArray arrayWithObjects:@"bnc.lt", @"app.link", @"test-app.link", nil];
879873
for (NSString* domain in branchDomains) {
880-
if ([userActivityURL containsString:domain])
874+
if ([userActivityURL containsString:domain]) {
881875
return YES;
876+
}
882877
}
883878
return NO;
884879
}
@@ -950,6 +945,19 @@ - (void)ignoreAppleSearchAdsTestData {
950945
#endif
951946
}
952947

948+
- (void)checkPasteboardOnInstall {
949+
[BNCPasteboard sharedInstance].checkOnInstall = YES;
950+
}
951+
952+
- (BOOL)willShowPasteboardToast {
953+
if (!self.preferenceHelper.identityID &&
954+
[BNCPasteboard sharedInstance].checkOnInstall &&
955+
[BNCPasteboard sharedInstance].isUrlOnPasteboard) {
956+
return YES;
957+
}
958+
return NO;
959+
}
960+
953961
- (void)checkAppleSearchAdsAttribution {
954962
#if !TARGET_OS_TV
955963
if (![BNCAppleSearchAds sharedInstance].enableAppleSearchAdsCheck) {

Branch-SDK/BranchConstants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ extern NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION;
5959
extern NSString * const BRANCH_REQUEST_KEY_LINK_IDENTIFIER;
6060
extern NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER;
6161
extern NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL;
62+
extern NSString * const BRANCH_REQUEST_KEY_LOCAL_URL;
63+
extern NSString * const BRANCH_REQUEST_KEY_INITIAL_REFERRER;
6264
extern NSString * const BRANCH_REQUEST_KEY_BRAND;
6365
extern NSString * const BRANCH_REQUEST_KEY_MODEL;
6466
extern NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH;

Branch-SDK/BranchConstants.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION = @"apple_ad_attribution_checked";
5656
NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER = @"spotlight_identifier";
5757
NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL = @"universal_link_url";
58+
NSString * const BRANCH_REQUEST_KEY_LOCAL_URL = @"local_url";
59+
NSString * const BRANCH_REQUEST_KEY_INITIAL_REFERRER = @"initial_referrer";
5860
NSString * const BRANCH_REQUEST_KEY_BRAND = @"brand";
5961
NSString * const BRANCH_REQUEST_KEY_MODEL = @"model";
6062
NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH = @"screen_width";

Branch-SDK/BranchInstallRequest.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import "BNCAppleReceipt.h"
1616
#import "BNCAppGroupsData.h"
1717
#import "BNCPartnerParameters.h"
18+
#import "BNCPasteboard.h"
1819

1920
@implementation BranchInstallRequest
2021

@@ -37,7 +38,7 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
3738
[self safeSetValue:preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:params];
3839
[self safeSetValue:preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:params];
3940
[self safeSetValue:preferenceHelper.universalLinkUrl forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:params];
40-
41+
[self safeSetValue:preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:params];
4142
[self safeSetValue:[[BNCAppleReceipt sharedInstance] installReceipt] forKey:BRANCH_REQUEST_KEY_APPLE_RECEIPT onDict:params];
4243
[self safeSetValue:[NSNumber numberWithBool:[[BNCAppleReceipt sharedInstance] isTestFlight]] forKey:BRANCH_REQUEST_KEY_APPLE_TESTFLIGHT onDict:params];
4344

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

71+
if ([BNCPasteboard sharedInstance].checkOnInstall) {
72+
NSURL *pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
73+
if (pasteboardURL) {
74+
[self safeSetValue:pasteboardURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:params];
75+
}
76+
}
77+
7078
NSString *appleAttributionToken = [BNCSystemObserver appleAttributionToken];
7179
if (appleAttributionToken) {
7280
preferenceHelper.appleAttributionTokenChecked = YES;

0 commit comments

Comments
 (0)