Skip to content

Commit

Permalink
Removed param urlString from BranchOpenRequest class
Browse files Browse the repository at this point in the history
urlString holds the same value as linkparams.referringURL. So removed urlString and adjusted other functions to use linkparams.referringURL instead.
  • Loading branch information
NidhiDixit09 committed Dec 3, 2024
1 parent f195d92 commit 943ab31
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 30 deletions.
30 changes: 15 additions & 15 deletions Sources/BranchSDK/BNCRequestFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ - (BOOL)isTrackingDisabled {
return Branch.trackingDisabled;
}

- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest {
- (NSDictionary *)dataForInstallWithLinkParams:(BranchOpenRequestLinkParams *) linkParams {
NSMutableDictionary *json = [NSMutableDictionary new];

// All requests
Expand All @@ -101,18 +101,18 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta
// Install and Open
[self addDeveloperUserIDToJSON:json];
[self addSystemObserverDataToJSON:json];
[self addOpenRequestDataToJSON:json fromRequestObject:installRequest];
[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 (installRequest.urlString && !installRequest.linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:installRequest.urlString];
if (linkParams.referringURL && !linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:linkParams.referringURL];
if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
[self safeSetValue:installRequest.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:installRequest.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 @@ -134,7 +134,7 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta
return json;
}

- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest {
- (NSDictionary *)dataForOpenWithLinkParams:(BranchOpenRequestLinkParams *) linkParams{
NSMutableDictionary *json = [NSMutableDictionary new];

// All requests
Expand All @@ -156,19 +156,19 @@ - (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest
// Install and Open
[self addDeveloperUserIDToJSON:json];
[self addSystemObserverDataToJSON:json];
[self addOpenRequestDataToJSON:json fromRequestObject:openRequest];
[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 (openRequest.urlString && !openRequest.linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:openRequest.urlString];
if (linkParams.referringURL && !linkParams.dropURLOpen) {
NSURL *url = [NSURL URLWithString:linkParams.referringURL];
if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
[self safeSetValue:openRequest.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:openRequest.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 @@ -305,12 +305,12 @@ - (void)addShortURLTokensToJSON:(NSMutableDictionary *)json isSpotlightRequest:(
json[BRANCH_REQUEST_KEY_SESSION_ID] = self.preferenceHelper.sessionID;
}

- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromRequestObject:(BranchOpenRequest *) openRequest{
- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromLinkParams:(BranchOpenRequestLinkParams *) linkParams{
json[BRANCH_REQUEST_KEY_DEBUG] = @(self.preferenceHelper.isDebug);
[self safeSetValue:self.preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:json];

[self safeSetValue:openRequest.linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json];
[self safeSetValue:openRequest.linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER 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];

}

Expand Down
6 changes: 2 additions & 4 deletions Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -2089,12 +2089,11 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
req = [[BranchInstallRequest alloc] initWithCallback:initSessionCallback];
}
req.callback = initSessionCallback;
req.urlString = params.referringURL;
req.linkParams = params;

[self.requestQueue insert:req at:0];

NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString];
NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link params %@", req, req.callback, req.linkParams];
[[BranchLogger shared] logDebug:message error:nil];

} else {
Expand All @@ -2103,14 +2102,13 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
if (params.referringURL) {
req = [[BranchOpenRequest alloc] initWithCallback:initSessionCallback];
req.callback = initSessionCallback;
req.urlString = params.referringURL;
req.linkParams = params;

// put it behind the one that's already on queue
[self.requestQueue insert:req at:1];

[[BranchLogger shared] logDebug:@"Link resolution request" error:nil];
NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString];
NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link params%@", req, req.callback, req.linkParams];
[[BranchLogger shared] logDebug:message error:nil];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/BranchSDK/BranchInstallRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (id)initWithCallback:(callbackWithStatus)callback {

- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *params = [factory dataForInstallWithRequestObject:self];
NSDictionary *params = [factory dataForInstallWithLinkParams:self.linkParams];

[serverInterface postRequest:params url:[[BNCServerAPI sharedInstance] installServiceURL] key:key callback:callback];
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/BranchSDK/BranchOpenRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall {

- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback {
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp];
NSDictionary *params = [factory dataForOpenWithRequestObject:self];
NSDictionary *params = [factory dataForOpenWithLinkParams:self.linkParams];

[serverInterface postRequest:params
url:[[BNCServerAPI sharedInstance] openServiceURL]
Expand Down Expand Up @@ -140,8 +140,8 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error {
}

NSString *referringURL = nil;
if (self.urlString.length > 0) {
referringURL = self.urlString;
if (self.linkParams.referringURL.length > 0) {
referringURL = self.linkParams.referringURL;
} else {
NSDictionary *sessionDataDict = [BNCEncodingUtils decodeJsonStringToDictionary:sessionData];
NSString *link = sessionDataDict[BRANCH_RESPONSE_KEY_BRANCH_REFERRING_LINK];
Expand Down Expand Up @@ -249,13 +249,13 @@ - (NSString *)getActionName {
- (instancetype)initWithCoder:(NSCoder *)decoder {
self = [super initWithCoder:decoder];
if (!self) return self;
self.urlString = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"];
self.linkParams.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"];
return self;
}

- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:self.urlString forKey:@"urlString"];
[coder encodeObject:self.linkParams.referringURL forKey:@"urlString"];
}

+ (BOOL)supportsSecureCoding {
Expand Down
4 changes: 2 additions & 2 deletions Sources/BranchSDK/Private/BNCRequestFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithBranchKey:(NSString *)key UUID:(NSString *)requestUUID TimeStamp:(NSNumber *)requestTimeStamp NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;

- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest;
- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest;
- (NSDictionary *)dataForInstallWithLinkParams:(BranchOpenRequestLinkParams *) linkParams;
- (NSDictionary *)dataForOpenWithLinkParams:(BranchOpenRequestLinkParams *) linkParams;

// Event data is passed in
- (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)dictionary;
Expand Down
5 changes: 2 additions & 3 deletions Sources/BranchSDK/Private/BranchOpenRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
@interface BranchOpenRequestLinkParams : NSObject
@property (copy, nonatomic) NSString *linkClickIdentifier;
@property (copy, nonatomic) NSString *spotlightIdentifier;
@property (copy, nonatomic) NSString *referringURL;
@property (copy, nonatomic) NSString *referringURL; // URL that triggered this install or open event
@property (assign, nonatomic) BOOL dropURLOpen;
@end

@interface BranchOpenRequest : BNCServerRequest

// URL that triggered this install or open event
@property (nonatomic, copy, readwrite) NSString *urlString;

@property (nonatomic, copy) callbackWithStatus callback;
@property (nonatomic, copy, readwrite) BranchOpenRequestLinkParams *linkParams;

Expand Down

0 comments on commit 943ab31

Please sign in to comment.