Skip to content

Commit

Permalink
Update the pasteboard handling
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-branch committed Sep 18, 2023
1 parent 5b43732 commit 69c84d0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 114 deletions.
46 changes: 0 additions & 46 deletions Branch-TestBed/Branch-SDK-Tests/BNCServerInterface.Test.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,52 +347,6 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount {
[self waitForExpectationsWithTimeout:1.0 handler:nil];
}

//==================================================================================
// TEST 09
// Test certifcate pinning functionality.

// We do NOT pin by default anymore.
//- (void) testCertificatePinning {
//
// [OHHTTPStubs removeAllStubs];
// BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
//
// XCTestExpectation* pinSuccess = [self expectationWithDescription:@"PinSuccess1"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://branch.io"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @200);
// [pinSuccess fulfill];
// }];
//
// XCTestExpectation* pinFail1 = [self expectationWithDescription:@"PinFail1"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://google.com"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @-999);
// [pinFail1 fulfill];
// }];
//
//#if 0
// // TODO: Fix so the end point so the test works on external (outside the Branch office) networks.
//
// XCTestExpectation* pinFail2 = [self expectationWithDescription:@"PinFail2"];
// [serverInterface getRequest:[NSDictionary new]
// url:@"https://internal-cert-pinning-test-470549067.us-west-1.elb.amazonaws.com/"
// key:@""
// callback:^ (BNCServerResponse*response, NSError*error) {
// XCTAssertEqualObjects(response.statusCode, @-999);
// //XCTAssertEqualObjects(response.statusCode, @200);
// [pinFail2 fulfill];
// }];
//#endif
//
// [self waitForExpectationsWithTimeout:10.0 handler:nil];
//}


//==================================================================================
// TEST 10
// Test mapping of X-Branch-Request-Id to [BNCServerResponse requestId]
Expand Down
3 changes: 2 additions & 1 deletion BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (NSString *)getAPIURL:(NSString *) endpoint {
return [[self getAPIBaseURL] stringByAppendingString:endpoint];
}

// TODO: reconsider this API, it's used to identify the behavior of referring URL query param handling. Not a good design IMHO.
// TODO: reconsider this API, it's used to identify the behavior of referring URL query param handling
- (NSString *)getEndpointFromURL:(NSString *)url {
NSString *APIBase = self.branchAPIURL;
if ([url hasPrefix:APIBase]) {
Expand Down Expand Up @@ -401,6 +401,7 @@ - (NSString *)initialReferrer {
- (void)setInitialReferrer:(NSString *)initialReferrer {
[self writeObjectToDefaults:BRANCH_REQUEST_KEY_INITIAL_REFERRER value:initialReferrer];
}

- (NSString *)sessionParams {
@synchronized (self) {
if (!_sessionParams) {
Expand Down
76 changes: 50 additions & 26 deletions BranchSDK/BNCRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "BNCAppGroupsData.h"
#import "BNCSKAdNetwork.h"
#import "BNCReferringURLUtility.h"
#import "BNCPasteboard.h"

@interface BNCRequestFactory()

Expand All @@ -46,6 +47,7 @@ @interface BNCRequestFactory()
@property (nonatomic, strong, readwrite) BNCAppGroupsData *appGroupsData;
@property (nonatomic, strong, readwrite) BNCSKAdNetwork *skAdNetwork;
@property (nonatomic, strong, readwrite) BNCAppleReceipt *appleReceipt;
@property (nonatomic, strong, readwrite) BNCPasteboard *pasteboard;

@end

Expand All @@ -69,6 +71,7 @@ - (instancetype)initWithBranchKey:(NSString *)key {
self.appGroupsData = [BNCAppGroupsData shared];
self.skAdNetwork = [BNCSKAdNetwork sharedInstance];
self.appleReceipt = [BNCAppleReceipt sharedInstance];
self.pasteboard = [BNCPasteboard sharedInstance];
}
return self;
}
Expand Down Expand Up @@ -102,14 +105,14 @@ - (NSDictionary *)dataForInstall {
[self addPreferenceHelperDataToJSON:json];
[self addPartnerParametersToJSON:json];
[self addAppleReceiptSourceToJSON:json];
[self addLocalURLToJSON:json];
[self addTimestampsToJSON:json];

[self addAppleAttributionTokenToJSON:json];

// Install Only
[self addAppleReceiptDataToJSON:json];
[self addAppClipDataToJSON:json];
[self addLocalURLToInstallJSON:json];

// TODO: refactor to simply request values for install
[self addReferringURLsToJSON:json forEndpoint:@"/v1/install"];
Expand Down Expand Up @@ -139,14 +142,14 @@ - (NSDictionary *)dataForOpen {
[self addPreferenceHelperDataToJSON:json];
[self addPartnerParametersToJSON:json];
[self addAppleReceiptSourceToJSON:json];
[self addLocalURLToJSON:json];
[self addTimestampsToJSON:json];

// Usually sent with install, but retry on open if it didn't get sent
[self addAppleAttributionTokenToJSON:json];

// Only for opens
[self addOpenTokensToJSON:json];
[self addLocalURLToOpenJSON:json];

// TODO: refactor to simply request values for open
[self addReferringURLsToJSON:json forEndpoint:@"/v1/open"];
Expand Down Expand Up @@ -195,13 +198,13 @@ - (NSDictionary *)dataForShortURLWithLinkDataDictionary:(NSMutableDictionary *)d
// All POST requests other than Events
[self addSDKVersionToJSON:json];

// TODO: is this required? Confirm with server team that we can remove this?
// TODO: is this required? Confirm with server team that we can remove this.
[self addV1DictionaryToJSON:json];

// TODO: metadata is very likely dropped at server
// TODO: metadata is very likely dropped at server. Confirm with server team.
[self addMetadataToJSON:json];

// TODO: These are optional fields in the server code. Is there value in sending it?
// TODO: These are optional fields in the server code. Can we drop these as well?
[self addShortURLTokensToJSON:json isSpotlightRequest:isSpotlightRequest];

return json;
Expand All @@ -225,10 +228,10 @@ - (NSDictionary *)dataForLATDWithDataDictionary:(NSMutableDictionary *)dictionar
// All POST requests other than Events
[self addSDKVersionToJSON:json];

// TODO: likely a subset of the V2 dictionary is sufficient, should we minimize it
// TODO: likely a subset of the V2 dictionary is sufficient, should we minimize it.
[self addV2DictionaryToJSON:json];

// TODO: probably remove this, this is a pull request
// TODO: probably remove this, this is a data pull request and likely does nothing.
[self addMetadataToJSON:json];

return json;
Expand Down Expand Up @@ -312,22 +315,48 @@ - (void)addPartnerParametersToJSON:(NSMutableDictionary *)json {
}
}

// NativeLink URL
// TODO: isn't this install only? Why was this code in the open request code? Bad inheritance design?
- (BOOL)addLocalURLToJSON:(NSMutableDictionary *)json {
- (void)addLocalURLToInstallJSON:(NSMutableDictionary *)json {
if ([BNCPasteboard sharedInstance].checkOnInstall) {
NSURL *pasteboardURL = nil;
if (@available(iOS 16.0, macCatalyst 16.0, *)) {
NSString *localURLString = [self.preferenceHelper localUrl];
if (localURLString){
// TODO: url was found in storage, remember to clear it
pasteboardURL = [[NSURL alloc] initWithString:localURLString];
} else {
pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
}
} else {
pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
}

if (pasteboardURL) {
[self safeSetValue:pasteboardURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:json];
[self clearLocalURLFromStorage];
}
}
}

// If the client uses a UIPasteControl, force a new open to fetch the payload
- (void)addLocalURLToOpenJSON:(NSMutableDictionary *)json {
if (@available(iOS 16.0, macCatalyst 16.0, *)) {
NSString *localURLString = [[BNCPreferenceHelper sharedInstance] localUrl];
if(localURLString){
NSURL *localURL = [[NSURL alloc] initWithString:localURLString];
if (localURL) {
[self safeSetValue:localURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:json];
// TODO: add logic status logic. Maybe a callback block indicating status?
//self.clearLocalURL = TRUE;
return YES;
if (localURLString){
// TODO: url was found in storage, remember to clear it
NSURL *pasteboardURL = [[NSURL alloc] initWithString:localURLString];
if (pasteboardURL) {
[self safeSetValue:pasteboardURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:json];
[self clearLocalURLFromStorage];
}
}
}
return NO;
}

- (void)clearLocalURLFromStorage {
self.preferenceHelper.localUrl = nil;
#if !TARGET_OS_TV
UIPasteboard.generalPasteboard.URL = nil;
#endif
}

- (void)addTimestampsToJSON:(NSMutableDictionary *)json {
Expand All @@ -341,7 +370,7 @@ - (void)addTimestampsToJSON:(NSMutableDictionary *)json {
json[@"latest_install_time"] = BNCWireFormatFromDate(self.application.currentInstallDate);
json[@"first_install_time"] = BNCWireFormatFromDate(self.application.firstInstallDate);

// TODO: can we remove this deprecated update flag?
// TODO: can we omit this deprecated update flag?
json[@"update"] = @(0);
}

Expand All @@ -363,12 +392,6 @@ - (void)addDefaultRequestDataToJSON:(NSMutableDictionary *)json {
if ([self isTrackingDisabled]) {
json[@"tracking_disabled"] = @(1);
}

// TODO: does anyone actually use this, it's set for every request
// omit field if value is NO
// if ([self isAppExtension]) {
// json[@"ios_extension"] = @(1);
// }
}

// event omits this from the top level
Expand All @@ -380,7 +403,8 @@ - (void)addMetadataToJSON:(NSMutableDictionary *)json {
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
[metadata bnc_safeAddEntriesFromDictionary:self.preferenceHelper.requestMetadataDictionary];

// TODO: confirm this call does nothing with the new design. copies existing metadata keys
// TODO: confirm this call does nothing with the new design.
// copies existing metadata keys, believe there's only one pass on this so it should be empty.
[metadata bnc_safeAddEntriesFromDictionary:json[BRANCH_REQUEST_KEY_STATE]];

if (metadata.count) {
Expand Down
1 change: 0 additions & 1 deletion BranchSDK/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ extern NSString * __nonnull const BNCSpotlightFeature;

+ (BOOL)branchKeyIsSet;

/// TODO: Add documentation.
@property (weak, nullable) NSObject<BranchDelegate>* delegate;

//@property (strong, nonatomic, nullable) BranchEvent *testEvent;
Expand Down
1 change: 1 addition & 0 deletions BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,7 @@ - (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
}
}

// TODO: can we deprecate and remove this, it doesn't work well.
// UI code, must run on main
- (void)automaticallyDeeplinkWithReferringParams:(NSDictionary *)latestReferringParams {
// Find any matched keys, then launch any controllers that match
Expand Down
2 changes: 0 additions & 2 deletions BranchSDK/BranchDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2017 Branch Metrics. All rights reserved.
//

// TODO: Add documentation

#if __has_feature(modules)
@import Foundation;
#else
Expand Down
24 changes: 0 additions & 24 deletions BranchSDK/BranchInstallRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,9 @@ - (id)initWithCallback:(callbackWithStatus)callback {
}

- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback {

// TODO: move this logic
super.clearLocalURL = NO;

BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key];
NSDictionary *params = [factory dataForInstall];

// TODO: figure out why this is different
// if ([BNCPasteboard sharedInstance].checkOnInstall) {
// NSURL *pasteboardURL = nil;
// if (@available(iOS 16.0, macCatalyst 16.0, *)) {
// NSString *localURLString = [[BNCPreferenceHelper sharedInstance] localUrl];
// if(localURLString){
// pasteboardURL = [[NSURL alloc] initWithString:localURLString];
// super.clearLocalURL = TRUE;
// } else {
// pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
// }
// } else {
// pasteboardURL = [[BNCPasteboard sharedInstance] checkForBranchLink];
// }
//
// if (pasteboardURL) {
// [self safeSetValue:pasteboardURL.absoluteString forKey:BRANCH_REQUEST_KEY_LOCAL_URL onDict:params];
// }
// }

[serverInterface postRequest:params url:[[BNCServerAPI sharedInstance] installServiceURL].absoluteString key:key callback:callback];
}

Expand Down
4 changes: 0 additions & 4 deletions BranchSDK/BranchOpenRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@interface BranchOpenRequest : BNCServerRequest

@property (nonatomic, copy) callbackWithStatus callback;
@property (assign, nonatomic) BOOL clearLocalURL;

+ (void) waitForOpenResponseLock;
+ (void) releaseOpenResponseLock;
Expand All @@ -21,7 +20,4 @@
- (id)initWithCallback:(callbackWithStatus)callback;
- (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall;

// TODO: move this Tune upgrade logic
//+ (NSNumber*) appUpdateState;

@end
10 changes: 1 addition & 9 deletions BranchSDK/BranchOpenRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall {
}

- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback {
// TODO: handle clearLocalURL, it's needs to be touched in two disparate locations...
self.clearLocalURL = NO;
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key];
NSDictionary *params = [factory dataForOpen];

Expand Down Expand Up @@ -173,6 +171,7 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error {

NSString *string = BNCStringFromWireFormat(data[BRANCH_RESPONSE_KEY_RANDOMIZED_BUNDLE_TOKEN]);
if (!string) {
// fallback to deprecated name. The old name was easily confused with the setIdentity, hence the name change.
// fallback to deprecated name. The old name was easily confused with the setIdentity, hence the name change.
string = BNCStringFromWireFormat(data[@"identity_id"]);
}
Expand All @@ -181,13 +180,6 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error {
preferenceHelper.randomizedBundleToken = string;
}

if (self.clearLocalURL) {
preferenceHelper.localUrl = nil;
#if !TARGET_OS_TV
UIPasteboard.generalPasteboard.URL = nil;
#endif
}

[BranchOpenRequest releaseOpenResponseLock];

if (self.isInstall) {
Expand Down
1 change: 0 additions & 1 deletion BranchSDK/BranchUniversalObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ - (void) removeFromSpotlightWithCallback:(void (^_Nullable)(NSError * _Nullable
#pragma mark - Dictionary Methods

- (NSDictionary *)getParamsForServerRequestWithAddedLinkProperties:(BranchLinkProperties *)linkProperties {
// TODO: Add warnings if controlParams contains non-control params
NSMutableDictionary *temp = self.dictionary;
[temp addEntriesFromDictionary:[linkProperties.controlParams copy]];
return temp;
Expand Down

0 comments on commit 69c84d0

Please sign in to comment.