Skip to content

Commit

Permalink
Added request uuid and request creation timestamps to v1/qr-code requ…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
NidhiDixit09 committed Oct 3, 2024
1 parent 5988a60 commit be28ff6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ - (void)testUUIDANDTimeStampPersistence {
XCTAssertTrue([timeStampFromEventObject isEqualToNumber:[(BranchEventRequest *)requestObject requestCreationTimeStamp]]);
}
if ([requestObject isKindOfClass:BranchOpenRequest.class]) {

XCTAssertTrue([uuidFromOpenObject isEqualToString:[(BranchOpenRequest *)requestObject requestUUID]]);
XCTAssertTrue([timeStampFromOpenObject isEqualToNumber:[(BranchOpenRequest *)requestObject requestCreationTimeStamp]]);
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/BranchSDK/BNCServerRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ @implementation BNCServerRequest

- (id) init {
if ((self = [super init])) {
NSDate *timeStampDate = [NSDate date];
_requestUUID = [self generateRequestUUIDFromDate:timeStampDate];
_requestCreationTimeStamp = BNCWireFormatFromDate(timeStampDate);
NSDate *timeStamp = [NSDate date];
_requestUUID = [BNCServerRequest generateRequestUUIDFromDate:timeStamp];
_requestCreationTimeStamp = BNCWireFormatFromDate(timeStamp);
}
return self;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ + (BOOL)supportsSecureCoding {
return YES;
}

- (NSString *) generateRequestUUIDFromDate:(NSDate *) localDate {
+ (NSString *) generateRequestUUIDFromDate:(NSDate *) localDate {
NSString *uuid = [[NSUUID UUID ] UUIDString];

NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
Expand Down
9 changes: 7 additions & 2 deletions Sources/BranchSDK/BranchQRCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#import "UIViewController+Branch.h"
#import "BranchLogger.h"
#import "BNCServerAPI.h"
#import "BranchConstants.h"
#import "BNCEncodingUtils.h"

@interface BranchQRCode()
@property (nonatomic, copy, readwrite) NSString *buoTitle;
Expand Down Expand Up @@ -91,6 +93,10 @@ - (void)getQRCodeAsData:(nullable BranchUniversalObject *)buo
parameters[@"data"] = [buo dictionary];
parameters[@"branch_key"] = [Branch branchKey];

NSDate *timestamp = [NSDate date];
parameters[BRANCH_REQUEST_KEY_REQUEST_CREATION_TIME_STAMP] = BNCWireFormatFromDate(timestamp);
parameters[BRANCH_REQUEST_KEY_REQUEST_UUID] = [BNCServerRequest generateRequestUUIDFromDate:timestamp];

NSData *cachedQRCode = [[BNCQRCodeCache sharedInstance] checkQRCodeCache:parameters];
if (cachedQRCode) {
completion(cachedQRCode, nil);
Expand Down Expand Up @@ -136,8 +142,7 @@ - (void)callQRCodeAPI:(nullable NSDictionary *)params

NSData *postData = [NSJSONSerialization dataWithJSONObject:params options:0 error:&error];
[request setHTTPBody:postData];

[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.", request.URL.absoluteString] error:nil];
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Network start operation %@.\n Body %@", request.URL.absoluteString, [BNCEncodingUtils prettyPrintJSON:params]] error:nil];
NSDate *startDate = [NSDate date];

NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
Expand Down
1 change: 1 addition & 0 deletions Sources/BranchSDK/Public/BNCServerRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback;
- (void)processResponse:(BNCServerResponse *)response error:(NSError *)error;
- (void)safeSetValue:(NSObject *)value forKey:(NSString *)key onDict:(NSMutableDictionary *)dict;
+ (NSString *) generateRequestUUIDFromDate:(NSDate *) localDate;
@end

0 comments on commit be28ff6

Please sign in to comment.