Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[In Progress] SDK - 2519 Open Request Input Params Refactor #1454

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 6 additions & 4 deletions Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ - (void)testBranchEventRequestArchive {

- (void)testBranchOpenRequestArchive {
BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:nil];
request.urlString = @"https://branch.io";
request.linkParams = [[BranchOpenRequestLinkParams alloc] init];
request.linkParams.referringURL = @"https://branch.io";

// archive the event
NSError *error = nil;
Expand All @@ -88,14 +89,15 @@ - (void)testBranchOpenRequestArchive {
XCTAssertTrue([object isKindOfClass:BranchOpenRequest.class]);
BranchOpenRequest *unarchivedRequest = (BranchOpenRequest *)object;

XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]);
XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]);
XCTAssertNil(unarchivedRequest.callback);
XCTAssertTrue([@"open" isEqualToString:[unarchivedRequest getActionName]]);
}

- (void)testBranchInstallRequestArchive {
BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:nil];
request.urlString = @"https://branch.io";
request.linkParams = [[BranchOpenRequestLinkParams alloc] init];
request.linkParams.referringURL = @"https://branch.io";

// archive the event
NSError *error = nil;
Expand All @@ -112,7 +114,7 @@ - (void)testBranchInstallRequestArchive {
XCTAssertTrue([object isKindOfClass:BranchInstallRequest.class]);
BranchInstallRequest *unarchivedRequest = (BranchInstallRequest *)object;

XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]);
XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]);
XCTAssertNil(unarchivedRequest.callback);
XCTAssertTrue([@"install" isEqualToString:[unarchivedRequest getActionName]]);
}
Expand Down
13 changes: 0 additions & 13 deletions Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,6 @@ - (void)testSetLastStrongMatchDate {
XCTAssertEqualObjects(expectedDate, actualDate);
}

- (void)testSetAppVersion {
NSString *expectedVersion = @"1.0.0";
[self.prefHelper setAppVersion: expectedVersion];

NSString *actualVersion = [self.prefHelper appVersion];
XCTAssertEqualObjects(expectedVersion, actualVersion);
}

- (void)testSetLocalUrl {
NSString *expectedLocalURL = @"https://local.example.com";
Expand Down Expand Up @@ -364,14 +357,8 @@ - (void)testClearTrackingInformation {
[self.prefHelper clearTrackingInformation];

XCTAssertNil(self.prefHelper.sessionID);
XCTAssertNil(self.prefHelper.linkClickIdentifier);
XCTAssertNil(self.prefHelper.spotlightIdentifier);
XCTAssertNil(self.prefHelper.referringURL);
XCTAssertNil(self.prefHelper.universalLinkUrl);
XCTAssertNil(self.prefHelper.initialReferrer);
XCTAssertNil(self.prefHelper.installParams);
XCTAssertNil(self.prefHelper.sessionParams);
XCTAssertNil(self.prefHelper.externalIntentURI);
XCTAssertNil(self.prefHelper.savedAnalyticsData);
XCTAssertNil(self.prefHelper.previousAppBuildDate);
XCTAssertEqual(self.prefHelper.requestMetadataDictionary.count, 0);
Expand Down
10 changes: 5 additions & 5 deletions Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)tearDown {

- (void)testInitWithBranchKeyNil {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil UUID:_requestUUID TimeStamp:_requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

// key is omitted when nil
Expand All @@ -40,7 +40,7 @@ - (void)testInitWithBranchKeyNil {

- (void)testInitWithBranchKeyEmpty {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

// empty string is allowed
Expand All @@ -52,7 +52,7 @@ - (void)testInitWithBranchKeyEmpty {

- (void)testInitWithBranchKey {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);

Expand All @@ -62,7 +62,7 @@ - (void)testInitWithBranchKey {

- (void)testDataForInstall {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
Expand All @@ -79,7 +79,7 @@ - (void)testDataForInstall {

- (void)testDataForOpen {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"];
NSDictionary *json = [factory dataForInstallWithLinkParams:nil];
XCTAssertNotNil(json);

XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
Expand Down
4 changes: 2 additions & 2 deletions Sources/BranchSDK/BNCAppGroupsData.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ - (NSDate *)getDateForKey:(NSString *)key {
return nil;
}

- (void)saveAppClipData {
- (void)saveAppClipData:(NSString *) referringURL {
if ([BNCSystemObserver isAppClip]) {

BNCApplication *application = [BNCApplication currentApplication];
Expand All @@ -79,7 +79,7 @@ - (void)saveAppClipData {

BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance];

NSString *url = preferenceHelper.referringURL;
NSString *url = referringURL;
NSString *token = preferenceHelper.randomizedDeviceToken;
NSString *bundleToken = preferenceHelper.randomizedBundleToken;

Expand Down
94 changes: 0 additions & 94 deletions Sources/BranchSDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ @interface BNCPreferenceHelper () {
NSOperationQueue *_persistPrefsQueue;
NSString *_lastSystemBuildVersion;
NSString *_browserUserAgentString;
NSString *_referringURL;
}

@property (strong, nonatomic) NSMutableDictionary *persistenceDict;
Expand All @@ -90,20 +89,15 @@ @implementation BNCPreferenceHelper
// since we override both setter and getter, these properties do not auto synthesize
@synthesize
lastRunBranchKey = _lastRunBranchKey,
appVersion = _appVersion,
randomizedDeviceToken = _randomizedDeviceToken,
sessionID = _sessionID,
spotlightIdentifier = _spotlightIdentifier,
randomizedBundleToken = _randomizedBundleToken,
linkClickIdentifier = _linkClickIdentifier,
userUrl = _userUrl,
userIdentity = _userIdentity,
sessionParams = _sessionParams,
installParams = _installParams,
universalLinkUrl = _universalLinkUrl,
initialReferrer = _initialReferrer,
localUrl = _localUrl,
externalIntentURI = _externalIntentURI,
isDebug = _isDebug,
retryCount = _retryCount,
retryInterval = _retryInterval,
Expand Down Expand Up @@ -220,20 +214,6 @@ - (void)setLastStrongMatchDate:(NSDate *)lastStrongMatchDate {
}
}

- (NSString *)appVersion {
if (!_appVersion) {
_appVersion = [self readStringFromDefaults:BRANCH_PREFS_KEY_APP_VERSION];
}
return _appVersion;
}

- (void)setAppVersion:(NSString *)appVersion {
if (![_appVersion isEqualToString:appVersion]) {
_appVersion = appVersion;
[self writeObjectToDefaults:BRANCH_PREFS_KEY_APP_VERSION value:appVersion];
}
}

- (NSString *)randomizedDeviceToken {
if (!_randomizedDeviceToken) {
NSString *tmp = [self readStringFromDefaults:BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN];
Expand Down Expand Up @@ -308,62 +288,6 @@ - (void)setUserIdentity:(NSString *)userIdentity {
[self writeObjectToDefaults:BRANCH_PREFS_KEY_IDENTITY value:userIdentity];
}

- (NSString *)linkClickIdentifier {
return [self readStringFromDefaults:BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER];
}

- (void)setLinkClickIdentifier:(NSString *)linkClickIdentifier {
[self writeObjectToDefaults:BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER value:linkClickIdentifier];
}

- (NSString *)spotlightIdentifier {
return [self readStringFromDefaults:BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER];
}

- (void)setSpotlightIdentifier:(NSString *)spotlightIdentifier {
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER value:spotlightIdentifier];
}

- (NSString *)externalIntentURI {
@synchronized(self) {
if (!_externalIntentURI) {
_externalIntentURI = [self readStringFromDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI];
}
return _externalIntentURI;
}
}

- (void)setExternalIntentURI:(NSString *)externalIntentURI {
@synchronized(self) {
if (externalIntentURI == nil || ![_externalIntentURI isEqualToString:externalIntentURI]) {
_externalIntentURI = externalIntentURI;
[self writeObjectToDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI value:externalIntentURI];
}
}
}

- (NSString*) referringURL {
@synchronized (self) {
if (!_referringURL) _referringURL = [self readStringFromDefaults:@"referringURL"];
return _referringURL;
}
}

- (void) setReferringURL:(NSString *)referringURL {
@synchronized (self) {
_referringURL = [referringURL copy];
[self writeObjectToDefaults:@"referringURL" value:_referringURL];
}
}

- (NSString *)universalLinkUrl {
return [self readStringFromDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL];
}

- (void)setUniversalLinkUrl:(NSString *)universalLinkUrl {
[self writeObjectToDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL value:universalLinkUrl];
}

- (NSString *)localUrl {
return [self readStringFromDefaults:BRANCH_PREFS_KEY_LOCAL_URL];
}
Expand Down Expand Up @@ -618,18 +542,6 @@ - (void) setSavedURLPatternListVersion:(NSInteger)URLPatternListVersion {
}
}

- (BOOL) dropURLOpen {
@synchronized(self) {
return [self readBoolFromDefaults:@"dropURLOpen"];
}
}

- (void) setDropURLOpen:(BOOL)value {
@synchronized(self) {
[self writeBoolToDefaults:@"dropURLOpen" value:value];
}
}

- (BOOL) trackingDisabled {
@synchronized(self) {
NSNumber *b = (id) [self readObjectFromDefaults:@"trackingDisabled"];
Expand Down Expand Up @@ -849,14 +761,8 @@ - (void) clearTrackingInformation {
self.randomizedBundleToken = nil;
*/
self.sessionID = nil;
self.linkClickIdentifier = nil;
self.spotlightIdentifier = nil;
self.referringURL = nil;
self.universalLinkUrl = nil;
self.initialReferrer = nil;
self.installParams = nil;
self.sessionParams = nil;
self.externalIntentURI = nil;
self.savedAnalyticsData = nil;
self.previousAppBuildDate = nil;
self.requestMetadataDictionary = nil;
Expand Down
36 changes: 18 additions & 18 deletions Sources/BranchSDK/BNCRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#import "BNCSKAdNetwork.h"
#import "BNCReferringURLUtility.h"
#import "BNCPasteboard.h"
#import "BranchOpenRequest.h"
#import "BranchInstallRequest.h"

@interface BNCRequestFactory()

Expand Down Expand Up @@ -80,7 +82,7 @@ - (BOOL)isTrackingDisabled {
return Branch.trackingDisabled;
}

- (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString {
- (NSDictionary *)dataForInstallWithLinkParams:(BranchOpenRequestLinkParams *) linkParams {
NSMutableDictionary *json = [NSMutableDictionary new];

// All requests
Expand All @@ -99,18 +101,18 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString {
// Install and Open
[self addDeveloperUserIDToJSON:json];
[self addSystemObserverDataToJSON:json];
[self addPreferenceHelperDataToJSON:json];
[self addOpenRequestDataToJSON:json fromLinkParams:linkParams];
[self addPartnerParametersToJSON:json];
[self addAppleReceiptSourceToJSON:json];
[self addTimestampsToJSON:json];

// Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri
if (urlString) {
NSURL *url = [NSURL URLWithString:urlString];
if (linkParams.referringURL && !linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:linkParams.referringURL];
if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
[self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
} else {
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json];
[self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json];
}
}

Expand All @@ -132,7 +134,7 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString {
return json;
}

- (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString {
- (NSDictionary *)dataForOpenWithLinkParams:(BranchOpenRequestLinkParams *) linkParams{
NSMutableDictionary *json = [NSMutableDictionary new];

// All requests
Expand All @@ -154,19 +156,19 @@ - (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString {
// Install and Open
[self addDeveloperUserIDToJSON:json];
[self addSystemObserverDataToJSON:json];
[self addPreferenceHelperDataToJSON:json];
[self addOpenRequestDataToJSON:json fromLinkParams:linkParams];
[self addPartnerParametersToJSON:json];
[self addAppleReceiptSourceToJSON:json];
[self addTimestampsToJSON:json];


// Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri
if (urlString) {
NSURL *url = [NSURL URLWithString:urlString];
if (linkParams.referringURL && !linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:linkParams.referringURL];
if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
[self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
} else {
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json];
[self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json];
}
}

Expand Down Expand Up @@ -303,15 +305,13 @@ - (void)addShortURLTokensToJSON:(NSMutableDictionary *)json isSpotlightRequest:(
json[BRANCH_REQUEST_KEY_SESSION_ID] = self.preferenceHelper.sessionID;
}

- (void)addPreferenceHelperDataToJSON:(NSMutableDictionary *)json {
- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromLinkParams:(BranchOpenRequestLinkParams *) linkParams{
json[BRANCH_REQUEST_KEY_DEBUG] = @(self.preferenceHelper.isDebug);

[self safeSetValue:self.preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json];
[self safeSetValue:self.preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json];
[self safeSetValue:self.preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:json];

// This was only on opens before, cause it can't exist on install.
[self safeSetValue:self.preferenceHelper.externalIntentURI forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json];
[self safeSetValue:linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json];
[self safeSetValue:linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json];

}

- (void)addSystemObserverDataToJSON:(NSMutableDictionary *)json {
Expand Down
2 changes: 1 addition & 1 deletion Sources/BranchSDK/BNCServerRequestQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ - (BranchOpenRequest *)findExistingInstallOrOpen {

// Install subclasses open, so only need to check open
// Request should not be the one added from archived queue
if ([request isKindOfClass:[BranchOpenRequest class]] && !((BranchOpenRequest *)request).isFromArchivedQueue) {
if ([request isKindOfClass:[BranchOpenRequest class]]) {
return (BranchOpenRequest *)request;
}
}
Expand Down
Loading
Loading