From dc8d0334b5c843a7f7591b34b560999fc857d5de Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:39:11 -0700 Subject: [PATCH 1/5] Fix for INTENG-21262 -> Remove archived request file from disk when those req. are added in queue for processing on app launch. -> When persist timer is fired and req queue is empty, delete cache file from disk. persistImmediately func was earlier returning without updating cache if req queue was empty. -> Added check fileExistsAtPath before removing it in func removeSaveFile. --- .../BNCServerRequestQueueTests.m | 24 +++++++++++++++++++ Sources/BranchSDK/BNCServerRequestQueue.m | 6 ++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m index 4d8664b82..ff1b5e256 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m @@ -25,6 +25,8 @@ - (id)unarchiveObjectFromData:(NSData *)data; // returns data in the legacy format - (NSData *)oldArchiveQueue:(NSArray *)queue; ++ (NSURL * _Nonnull) URLForQueueFile; + @end @interface BNCServerRequestQueueTests : XCTestCase @@ -157,4 +159,26 @@ - (void)testOldArchiveArrayOfInvalidObjects { XCTAssert(unarchived.count == 2); } +- (void)testMultipleRequests { + BranchEventRequest *eventObject = [BranchEventRequest new]; + BranchOpenRequest *openObject = [BranchOpenRequest new]; + + [_queue enqueue: eventObject]; + [_queue enqueue: openObject]; + [_queue persistImmediately]; + + NSMutableArray *decodedQueue = nil; + NSData *data = [NSData dataWithContentsOfURL:[BNCServerRequestQueue URLForQueueFile] options:0 error:nil]; + if (data) { + decodedQueue = [_queue unarchiveQueueFromData:data]; + } + XCTAssert([decodedQueue count] == 2); + + [_queue remove:eventObject]; + [_queue remove:openObject]; + [_queue persistImmediately]; + // Request Queue is empty. So there should not be any queue file on disk. + XCTAssert([NSFileManager.defaultManager fileExistsAtPath:[[BNCServerRequestQueue URLForQueueFile] path]] == NO); +} + @end diff --git a/Sources/BranchSDK/BNCServerRequestQueue.m b/Sources/BranchSDK/BNCServerRequestQueue.m index 2fefbc419..259325b6b 100755 --- a/Sources/BranchSDK/BNCServerRequestQueue.m +++ b/Sources/BranchSDK/BNCServerRequestQueue.m @@ -217,6 +217,8 @@ - (void)cancelTimer { - (void)persistImmediately { @synchronized (self) { if (!self.queue || self.queue.count == 0) { + //No more requests. Delete cached queue file. + [self removeSaveFile]; return; } NSArray *queueCopy = [self.queue copy]; @@ -287,6 +289,8 @@ - (void)retrieve { } } self.queue = decodedQueue; + // Requests are loaded into queue now. Delete queue file stored on disk. + [self removeSaveFile]; } } } @@ -294,7 +298,7 @@ - (void)retrieve { // It's been reported that unarchive can fail in some situations. In that case, remove the queued requests file. - (void)removeSaveFile { NSURL *fileURL = [BNCServerRequestQueue URLForQueueFile]; - if (fileURL) { + if (fileURL && [NSFileManager.defaultManager fileExistsAtPath:[fileURL path]]) { NSError *error; [NSFileManager.defaultManager removeItemAtURL:fileURL error:&error]; From 0ccfb9649c7a37387984fa0cb1c2b36f16357b22 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 24 Sep 2024 08:40:51 -0700 Subject: [PATCH 2/5] Removed deletion of file if queue is empty because req are added only on cold launch. --- Sources/BranchSDK/BNCServerRequestQueue.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/BranchSDK/BNCServerRequestQueue.m b/Sources/BranchSDK/BNCServerRequestQueue.m index 259325b6b..2147f0fe8 100755 --- a/Sources/BranchSDK/BNCServerRequestQueue.m +++ b/Sources/BranchSDK/BNCServerRequestQueue.m @@ -217,8 +217,6 @@ - (void)cancelTimer { - (void)persistImmediately { @synchronized (self) { if (!self.queue || self.queue.count == 0) { - //No more requests. Delete cached queue file. - [self removeSaveFile]; return; } NSArray *queueCopy = [self.queue copy]; @@ -298,7 +296,7 @@ - (void)retrieve { // It's been reported that unarchive can fail in some situations. In that case, remove the queued requests file. - (void)removeSaveFile { NSURL *fileURL = [BNCServerRequestQueue URLForQueueFile]; - if (fileURL && [NSFileManager.defaultManager fileExistsAtPath:[fileURL path]]) { + if (fileURL) { NSError *error; [NSFileManager.defaultManager removeItemAtURL:fileURL error:&error]; From eb6dc7e3112598a5da5a84bd274c15c1163b0231 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 24 Sep 2024 08:47:52 -0700 Subject: [PATCH 3/5] Updated unit test. --- .../Branch-SDK-Tests/BNCServerRequestQueueTests.m | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m index ff1b5e256..d99a1be86 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m @@ -26,6 +26,7 @@ - (id)unarchiveObjectFromData:(NSData *)data; - (NSData *)oldArchiveQueue:(NSArray *)queue; + (NSURL * _Nonnull) URLForQueueFile; +- (void)retrieve; @end @@ -173,11 +174,12 @@ - (void)testMultipleRequests { decodedQueue = [_queue unarchiveQueueFromData:data]; } XCTAssert([decodedQueue count] == 2); - - [_queue remove:eventObject]; - [_queue remove:openObject]; - [_queue persistImmediately]; - // Request Queue is empty. So there should not be any queue file on disk. + [_queue clearQueue]; + XCTAssert([_queue queueDepth] == 0); + [_queue retrieve]; + XCTAssert([_queue queueDepth] == 2); + + // Request are loaded. So there should not be any queue file on disk. XCTAssert([NSFileManager.defaultManager fileExistsAtPath:[[BNCServerRequestQueue URLForQueueFile] path]] == NO); } From 3c694a0c179ee8ea919d2806d3d696bef2d6e985 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:15:31 -0700 Subject: [PATCH 4/5] Updated version for Release 3.6.3 --- BranchSDK.podspec | 2 +- BranchSDK.xcodeproj/project.pbxproj | 12 ++++++------ ChangeLog.md | 3 +++ Sources/BranchSDK/BNCConfig.m | 2 +- scripts/version.sh | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/BranchSDK.podspec b/BranchSDK.podspec index 51834cb76..de2775d88 100644 --- a/BranchSDK.podspec +++ b/BranchSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BranchSDK" - s.version = "3.6.2" + s.version = "3.6.3" s.summary = "Create an HTTP URL for any piece of content in your app" s.description = <<-DESC - Want the highest possible conversions on your sharing feature? diff --git a/BranchSDK.xcodeproj/project.pbxproj b/BranchSDK.xcodeproj/project.pbxproj index 4cc3e30c3..528cd9ce6 100644 --- a/BranchSDK.xcodeproj/project.pbxproj +++ b/BranchSDK.xcodeproj/project.pbxproj @@ -1974,7 +1974,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2009,7 +2009,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2215,7 +2215,7 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2254,7 +2254,7 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2291,7 +2291,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2326,7 +2326,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.2; + MARKETING_VERSION = 3.6.3; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, diff --git a/ChangeLog.md b/ChangeLog.md index d082a2f74..29149b2f2 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ Branch iOS SDK Change Log +v.3.6.3 +- Fix for duplicate purchase events created from archived request queue on disk. + v.3.6.2 - Fix for issue which was sending an extra open request on cold app launch. - Updated fix for cold link launch when using deferred initialization and an AppDelegate only app. diff --git a/Sources/BranchSDK/BNCConfig.m b/Sources/BranchSDK/BNCConfig.m index cbba9b378..2b661effc 100644 --- a/Sources/BranchSDK/BNCConfig.m +++ b/Sources/BranchSDK/BNCConfig.m @@ -8,7 +8,7 @@ #include "BNCConfig.h" -NSString * const BNC_SDK_VERSION = @"3.6.2"; +NSString * const BNC_SDK_VERSION = @"3.6.3"; NSString * const BNC_LINK_URL = @"https://bnc.lt"; NSString * const BNC_CDN_URL = @"https://cdn.branch.io"; diff --git a/scripts/version.sh b/scripts/version.sh index 952184f43..70c4ee231 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -30,7 +30,7 @@ Options: USAGE } -version=3.6.2 +version=3.6.3 prev_version="$version" if (( $# == 0 )); then From dc6907fa1b9284349d12a23573057cdd9762b2c1 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:21:59 -0700 Subject: [PATCH 5/5] Fixed ChangeLog entry. --- ChangeLog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 29149b2f2..0b3065d4a 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,7 +1,7 @@ Branch iOS SDK Change Log v.3.6.3 -- Fix for duplicate purchase events created from archived request queue on disk. +- Fix for duplicate events created from archived request queue on disk. v.3.6.2 - Fix for issue which was sending an extra open request on cold app launch.