Skip to content

Commit 3d7aa5f

Browse files
committed
CORE-2088 backport the pasteboard feature
1 parent a8eed23 commit 3d7aa5f

File tree

9 files changed

+118
-27
lines changed

9 files changed

+118
-27
lines changed

Branch-SDK/BNCPasteboard.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
// For v1, we only allow check on install requests
16+
@property (nonatomic,assign) BOOL checkOnInstall;
17+
18+
- (nullable NSURL *)checkForBranchLink;
19+
20+
+ (BNCPasteboard *)sharedInstance;
21+
22+
@end
23+
24+
NS_ASSUME_NONNULL_END

Branch-SDK/BNCPasteboard.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
12+
@implementation BNCPasteboard
13+
14+
+ (BNCPasteboard *)sharedInstance {
15+
static BNCPasteboard *pasteboard;
16+
static dispatch_once_t onceToken;
17+
dispatch_once(&onceToken, ^{
18+
pasteboard = [BNCPasteboard new];
19+
});
20+
return pasteboard;
21+
}
22+
23+
- (instancetype)init {
24+
self = [super init];
25+
if (self) {
26+
self.checkOnInstall = NO;
27+
}
28+
return self;
29+
}
30+
31+
- (nullable NSURL *)checkForBranchLink {
32+
// consider limiting this check to iOS 15+
33+
if (@available(iOS 10.0, *)) {
34+
if ([UIPasteboard.generalPasteboard hasURLs]) {
35+
36+
// triggers the end user toast message
37+
NSURL *tmp = UIPasteboard.generalPasteboard.URL;
38+
if ([self isProbableBranchLink:tmp]) {
39+
return tmp;
40+
}
41+
}
42+
}
43+
return nil;
44+
}
45+
46+
- (BOOL)isProbableBranchLink:(NSURL *)url {
47+
// TODO: check against info.plist
48+
return YES;
49+
}
50+
51+
@end

Branch-SDK/Branch.h

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

679+
/**
680+
Checks the pasteboard for a Branch Link.
681+
This copied Branch Link in the install request and can provide deeplink data.
682+
683+
Note, this will display a toast message to the end user.
684+
*/
685+
- (void)checkPasteboardForBranchLinkOnInstall;
686+
679687
/**
680688
Set the AppGroup used to share data between the App Clip and the Full App.
681689

Branch-SDK/Branch.m

Lines changed: 15 additions & 27 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"
@@ -800,26 +801,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS
800801

801802
[self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier];
802803

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;
804+
return [self isBranchLink:urlString];
823805
}
824806

825807
- (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
@@ -860,25 +842,27 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS
860842
return spotlightIdentifier != nil;
861843
}
862844

863-
- (BOOL)isBranchLink:(NSString*)urlString {
864-
id branchUniversalLinkDomains = [self.preferenceHelper getBranchUniversalLinkDomains];
865-
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] &&
866-
[urlString containsString:branchUniversalLinkDomains]) {
845+
- (BOOL)isBranchLink:(NSString *)urlString {
846+
id branchUniversalLinkDomains = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"branch_universal_link_domains"];
847+
848+
// check list in bundle
849+
if ([branchUniversalLinkDomains isKindOfClass:[NSString class]] && [urlString containsString:branchUniversalLinkDomains]) {
867850
return YES;
868-
}
869-
else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
851+
} else if ([branchUniversalLinkDomains isKindOfClass:[NSArray class]]) {
870852
for (id oneDomain in branchUniversalLinkDomains) {
871853
if ([oneDomain isKindOfClass:[NSString class]] && [urlString containsString:oneDomain]) {
872854
return YES;
873855
}
874856
}
875857
}
876858

859+
// check default urls
877860
NSString *userActivityURL = urlString;
878861
NSArray *branchDomains = [NSArray arrayWithObjects:@"bnc.lt", @"app.link", @"test-app.link", nil];
879862
for (NSString* domain in branchDomains) {
880-
if ([userActivityURL containsString:domain])
863+
if ([userActivityURL containsString:domain]) {
881864
return YES;
865+
}
882866
}
883867
return NO;
884868
}
@@ -950,6 +934,10 @@ - (void)ignoreAppleSearchAdsTestData {
950934
#endif
951935
}
952936

937+
- (void)checkPasteboardForBranchLinkOnInstall {
938+
[BNCPasteboard sharedInstance].checkOnInstall = YES;
939+
}
940+
953941
- (void)checkAppleSearchAdsAttribution {
954942
#if !TARGET_OS_TV
955943
if (![BNCAppleSearchAds sharedInstance].enableAppleSearchAdsCheck) {

Branch-SDK/BranchConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ 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;
6263
extern NSString * const BRANCH_REQUEST_KEY_BRAND;
6364
extern NSString * const BRANCH_REQUEST_KEY_MODEL;
6465
extern NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH;

Branch-SDK/BranchConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
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";
5859
NSString * const BRANCH_REQUEST_KEY_BRAND = @"brand";
5960
NSString * const BRANCH_REQUEST_KEY_MODEL = @"model";
6061
NSString * const BRANCH_REQUEST_KEY_SCREEN_WIDTH = @"screen_width";

Branch-SDK/BranchInstallRequest.m

Lines changed: 8 additions & 0 deletions
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

@@ -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;

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
5F3D6718233061CB00454FF1 /* BranchCrossPlatformIDTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F3D6717233061CB00454FF1 /* BranchCrossPlatformIDTests.m */; };
183183
5F3D671B233062FD00454FF1 /* BNCJsonLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F3D671A233062FD00454FF1 /* BNCJsonLoader.m */; };
184184
5F3D671C233062FD00454FF1 /* BNCJsonLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F3D671A233062FD00454FF1 /* BNCJsonLoader.m */; };
185+
5F4101F526851DC7003699AD /* BNCPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F4101F326851DC7003699AD /* BNCPasteboard.h */; };
186+
5F4101F626851DC7003699AD /* BNCPasteboard.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F4101F426851DC7003699AD /* BNCPasteboard.m */; };
185187
5F42763325DB3694005B9BBC /* AdServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F42763225DB3694005B9BBC /* AdServices.framework */; };
186188
5F437E35237DDF770052064B /* BNCTelephony.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F437E33237DDF770052064B /* BNCTelephony.h */; };
187189
5F437E36237DDF770052064B /* BNCTelephony.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F437E34237DDF770052064B /* BNCTelephony.m */; };
@@ -495,6 +497,8 @@
495497
5F3D6717233061CB00454FF1 /* BranchCrossPlatformIDTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BranchCrossPlatformIDTests.m; sourceTree = "<group>"; };
496498
5F3D6719233062FD00454FF1 /* BNCJsonLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCJsonLoader.h; sourceTree = "<group>"; };
497499
5F3D671A233062FD00454FF1 /* BNCJsonLoader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCJsonLoader.m; sourceTree = "<group>"; };
500+
5F4101F326851DC7003699AD /* BNCPasteboard.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCPasteboard.h; sourceTree = "<group>"; };
501+
5F4101F426851DC7003699AD /* BNCPasteboard.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCPasteboard.m; sourceTree = "<group>"; };
498502
5F42763225DB3694005B9BBC /* AdServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdServices.framework; path = System/Library/Frameworks/AdServices.framework; sourceTree = SDKROOT; };
499503
5F437E33237DDF770052064B /* BNCTelephony.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNCTelephony.h; sourceTree = "<group>"; };
500504
5F437E34237DDF770052064B /* BNCTelephony.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCTelephony.m; sourceTree = "<group>"; };
@@ -989,6 +993,8 @@
989993
5F437E34237DDF770052064B /* BNCTelephony.m */,
990994
5F92B2372383703700CA909B /* BNCLocale.h */,
991995
5F92B2382383703700CA909B /* BNCLocale.m */,
996+
5F4101F326851DC7003699AD /* BNCPasteboard.h */,
997+
5F4101F426851DC7003699AD /* BNCPasteboard.m */,
992998
5FB0AA69231875B400A0F9EA /* BNCUserAgentCollector.h */,
993999
5FB0AA6A231875B500A0F9EA /* BNCUserAgentCollector.m */,
9941000
464EA3991ACB38EC000E4094 /* BNCEncodingUtils.h */,
@@ -1114,6 +1120,7 @@
11141120
5F38022024DCC2E800E6FAFD /* BranchLogoutRequest.h in Headers */,
11151121
5F38023124DCC2E800E6FAFD /* BNCNetworkService.h in Headers */,
11161122
5F38021624DCC2E800E6FAFD /* BranchSpotlightUrlRequest.h in Headers */,
1123+
5F4101F526851DC7003699AD /* BNCPasteboard.h in Headers */,
11171124
4DCAC8181F426F7C00405D1D /* BranchLinkProperties.h in Headers */,
11181125
5F38022724DCC2E800E6FAFD /* BranchRedeemRewardsRequest.h in Headers */,
11191126
4DCAC81A1F426F7C00405D1D /* BranchUniversalObject.h in Headers */,
@@ -1427,6 +1434,7 @@
14271434
466B58551B17779C00A69EDE /* Branch.m in Sources */,
14281435
5F437E3E237E03C00052064B /* BNCDeviceSystem.m in Sources */,
14291436
5F38023B24DCC2E800E6FAFD /* BranchContentDiscoverer.m in Sources */,
1437+
5F4101F626851DC7003699AD /* BNCPasteboard.m in Sources */,
14301438
4DBC88651F3A55B700E119BF /* NSString+Branch.m in Sources */,
14311439
54FF1F8E1BD1D4AE0004CE2E /* BranchUniversalObject.m in Sources */,
14321440
4DA577181E67B1D600A43BDD /* BNCLog.m in Sources */,

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ - (BOOL)application:(UIApplication *)application
5151
// partner parameter sample
5252
//[branch addFacebookPartnerParameterWithName:@"em" value:@"11234e56af071e9c79927651156bd7a10bca8ac34672aba121056e2698ee7088"];
5353

54+
[branch checkPasteboardForBranchLinkOnInstall];
55+
5456
/*
5557
* Required: Initialize Branch, passing a deep link handler block:
5658
*/

0 commit comments

Comments
 (0)