diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m deleted file mode 100644 index 3dbbdd4fe..000000000 --- a/Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m +++ /dev/null @@ -1,372 +0,0 @@ -// -// BNCServerRequestQueueTests.m -// Branch-SDK-Tests -// -// Created by Ernest Cho on 5/14/21. -// Copyright © 2021 Branch, Inc. All rights reserved. -// - -#import -#import "BNCServerRequestQueue.h" -#import "BNCServerRequest.h" - -// Analytics requests -#import "BranchInstallRequest.h" -#import "BranchOpenRequest.h" -#import "BranchEvent.h" -#import "BranchShortURLRequest.h" -#import "BranchLATDRequest.h" - -@interface BNCServerRequestQueue () -- (NSData *)archiveQueue:(NSArray *)queue; -- (NSMutableArray *)unarchiveQueueFromData:(NSData *)data; - -- (NSData *)archiveObject:(NSObject *)object; -- (id)unarchiveObjectFromData:(NSData *)data; - -// returns data in the legacy format -- (NSData *)oldArchiveQueue:(NSArray *)queue; - -+ (NSURL * _Nonnull) URLForQueueFile; -- (void)retrieve; - -@end - -@interface BNCServerRequestQueueTests : XCTestCase -@property (nonatomic, strong, readwrite) BNCServerRequestQueue *queue; -@end - -@implementation BNCServerRequestQueueTests - -- (void)setUp { - self.queue = [BNCServerRequestQueue new]; -} - -- (void)tearDown { - self.queue = nil; -} - -- (NSArray *)getQueueCachedOnDisk { - NSMutableArray *decodedQueue = nil; - NSData *data = [NSData dataWithContentsOfURL:[BNCServerRequestQueue URLForQueueFile] options:0 error:nil]; - if (data) { - decodedQueue = [_queue unarchiveQueueFromData:data]; - } - return decodedQueue; -} - -- (void)testArchiveNil { - NSString *object = nil; - - NSData *archived = [self.queue archiveObject:object]; - XCTAssertNotNil(archived); - - NSString *unarchived = [self.queue unarchiveObjectFromData:archived]; - XCTAssertNil(unarchived); -} - -- (void)testArchiveString { - NSString *object = @"Hello World"; - - NSData *archived = [self.queue archiveObject:object]; - XCTAssertNotNil(archived); - - NSString *unarchived = [self.queue unarchiveObjectFromData:archived]; - XCTAssertNotNil(unarchived); - XCTAssert([object isEqual:unarchived]); -} - -- (void)testArchiveInstallRequest { - BranchInstallRequest *object = [BranchInstallRequest new]; - - NSData *archived = [self.queue archiveObject:object]; - XCTAssertNotNil(archived); - - BranchInstallRequest *unarchived = [self.queue unarchiveObjectFromData:archived]; - XCTAssertNotNil(unarchived); - XCTAssert([unarchived isKindOfClass:[BranchInstallRequest class]]); - - // The request object is not very test friendly, so comparing the two is not helpful at the moment -} - -- (void)testArchiveOpenRequest { - BranchOpenRequest *object = [BranchOpenRequest new]; - - NSData *archived = [self.queue archiveObject:object]; - XCTAssertNotNil(archived); - - BranchOpenRequest *unarchived = [self.queue unarchiveObjectFromData:archived]; - XCTAssertNotNil(unarchived); - XCTAssert([unarchived isKindOfClass:[BranchOpenRequest class]]); - - // The request object is not very test friendly, so comparing the two is not helpful at the moment -} - -- (void)testArchiveEventRequest { - BranchEventRequest *object = [BranchEventRequest new]; - - NSData *archived = [self.queue archiveObject:object]; - XCTAssertNotNil(archived); - - BranchEventRequest *unarchived = [self.queue unarchiveObjectFromData:archived]; - XCTAssertNotNil(unarchived); - XCTAssert([unarchived isKindOfClass:[BranchEventRequest class]]); - - // The request object is not very test friendly, so comparing the two is not helpful at the moment -} - -- (void)testArchiveArrayOfRequests { - NSMutableArray *tmp = [NSMutableArray new]; - [tmp addObject:[BranchOpenRequest new]]; - [tmp addObject:[BranchEventRequest new]]; - - NSData *data = [self.queue archiveQueue:tmp]; - XCTAssertNotNil(data); - - NSMutableArray *unarchived = [self.queue unarchiveQueueFromData:data]; - XCTAssertNotNil(unarchived); - XCTAssert(unarchived.count == 2); -} - -- (void)testOldArchiveArrayOfRequests { - NSMutableArray *tmp = [NSMutableArray new]; - [tmp addObject:[BranchOpenRequest new]]; - [tmp addObject:[BranchEventRequest new]]; - - NSData *data = [self.queue oldArchiveQueue:tmp]; - XCTAssertNotNil(data); - - NSMutableArray *unarchived = [self.queue unarchiveQueueFromData:data]; - XCTAssertNotNil(unarchived); - XCTAssert(unarchived.count == 2); -} - -- (void)testArchiveArrayOfInvalidObjects { - NSMutableArray *tmp = [NSMutableArray new]; - [tmp addObject:[BranchOpenRequest new]]; - [tmp addObject:@"Hello World"]; - [tmp addObject:[BranchEventRequest new]]; - - NSData *data = [self.queue archiveQueue:tmp]; - XCTAssertNotNil(data); - - NSMutableArray *unarchived = [self.queue unarchiveQueueFromData:data]; - - XCTAssertNotNil(unarchived); - XCTAssert(unarchived.count == 2); -} - -- (void)testOldArchiveArrayOfInvalidObjects { - NSMutableArray *tmp = [NSMutableArray new]; - [tmp addObject:[BranchOpenRequest new]]; - [tmp addObject:@"Hello World"]; - [tmp addObject:[BranchEventRequest new]]; - - NSData *data = [self.queue oldArchiveQueue:tmp]; - XCTAssertNotNil(data); - - NSMutableArray *unarchived = [self.queue unarchiveQueueFromData:data]; - - XCTAssertNotNil(unarchived); - XCTAssert(unarchived.count == 2); -} - -- (void)testMultipleRequests { - BranchEventRequest *eventObject = [BranchEventRequest new]; - BranchOpenRequest *openObject = [BranchOpenRequest new]; - - [_queue enqueue: eventObject]; - [_queue enqueue: openObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - XCTAssert([decodedQueue count] == 2); - [_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); -} - -- (void)testUUIDANDTimeStampPersistence { - BranchEventRequest *eventObject = [BranchEventRequest new]; - BranchOpenRequest *openObject = [BranchOpenRequest new]; - NSString *uuidFromEventObject = eventObject.requestUUID; - NSNumber *timeStampFromEventObject = eventObject.requestCreationTimeStamp; - NSString *uuidFromOpenObject = openObject.requestUUID; - NSNumber *timeStampFromOpenObject = openObject.requestCreationTimeStamp; - - XCTAssertTrue(![uuidFromEventObject isEqualToString:uuidFromOpenObject]); - - [_queue enqueue: eventObject]; - [_queue enqueue: openObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchEventRequest.class]) { - XCTAssertTrue([uuidFromEventObject isEqualToString:[(BranchEventRequest *)requestObject requestUUID]]); - XCTAssertTrue([timeStampFromEventObject isEqualToNumber:[(BranchEventRequest *)requestObject requestCreationTimeStamp]]); - } - if ([requestObject isKindOfClass:BranchOpenRequest.class]) { - XCTAssertTrue([uuidFromOpenObject isEqualToString:[(BranchOpenRequest *)requestObject requestUUID]]); - XCTAssertTrue([timeStampFromOpenObject isEqualToNumber:[(BranchOpenRequest *)requestObject requestCreationTimeStamp]]); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForOpen { - BranchOpenRequest *openObject = [[BranchOpenRequest alloc] init]; - BranchOpenRequest *openWithCallbackObject = [[BranchOpenRequest alloc] initWithCallback:^(BOOL changed, NSError * _Nullable error) {}]; - openObject.urlString = @"https://www.branch.io"; - openWithCallbackObject.urlString = @"https://www.branch.testWithCallback.io"; - [_queue enqueue: openObject]; - [_queue enqueue: openWithCallbackObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchOpenRequest.class]) { - BranchOpenRequest *tmpCopy = (BranchOpenRequest *)requestObject; - if ([tmpCopy.urlString isEqualToString:openObject.urlString]) { - XCTAssertTrue([tmpCopy.requestUUID isEqualToString:openObject.requestUUID]); - XCTAssertTrue([tmpCopy.requestCreationTimeStamp isEqualToNumber:openObject.requestCreationTimeStamp]); - } else if ([tmpCopy.urlString isEqualToString:openWithCallbackObject.urlString]) { - XCTAssertTrue([tmpCopy.requestUUID isEqualToString:openWithCallbackObject.requestUUID]); - XCTAssertTrue([tmpCopy.requestCreationTimeStamp isEqualToNumber:openWithCallbackObject.requestCreationTimeStamp]); - } else { - XCTFail("Invalid URL found"); - } - - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForInstall { - BranchInstallRequest *installObject = [[BranchInstallRequest alloc] init]; - BranchInstallRequest *installWithCallbackObject = [[BranchInstallRequest alloc] initWithCallback:^(BOOL changed, NSError * _Nullable error) {}]; - installObject.urlString = @"https://www.branch.io"; - installWithCallbackObject.urlString = @"https://www.branch.testWithCallback.io"; - [_queue enqueue: installObject]; - [_queue enqueue: installWithCallbackObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchInstallRequest.class]) { - BranchInstallRequest *tmpCopy = (BranchInstallRequest *)requestObject; - if ([tmpCopy.urlString isEqualToString:installObject.urlString]) { - XCTAssertTrue([tmpCopy.requestUUID isEqualToString:installObject.requestUUID]); - XCTAssertTrue([tmpCopy.requestCreationTimeStamp isEqualToNumber:installObject.requestCreationTimeStamp]); - } else if ([tmpCopy.urlString isEqualToString:installWithCallbackObject.urlString]) { - XCTAssertTrue([tmpCopy.requestUUID isEqualToString:installWithCallbackObject.requestUUID]); - XCTAssertTrue([tmpCopy.requestCreationTimeStamp isEqualToNumber:installWithCallbackObject.requestCreationTimeStamp]); - } else { - XCTFail("Invalid URL found"); - } - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForEvent { - BranchEventRequest *eventObject = [[BranchEventRequest alloc] init]; - [_queue enqueue: eventObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchEventRequest.class]) { - XCTAssertTrue([eventObject.requestUUID isEqualToString:((BranchEventRequest *)requestObject).requestUUID]); - XCTAssertTrue([eventObject.requestCreationTimeStamp isEqualToNumber:((BranchEventRequest *)requestObject).requestCreationTimeStamp]); - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForEventWithCallback { - - NSURL *url = [NSURL URLWithString:@"https://api3.branch.io/v2/event/standard"]; - BranchEventRequest *eventObject = [[BranchEventRequest alloc] initWithServerURL:url eventDictionary:nil completion:nil]; - - [_queue enqueue: eventObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchEventRequest.class]) { - XCTAssertTrue([eventObject.requestUUID isEqualToString:((BranchEventRequest *)requestObject).requestUUID]); - XCTAssertTrue([eventObject.requestCreationTimeStamp isEqualToNumber:((BranchEventRequest *)requestObject).requestCreationTimeStamp]); - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForShortURL { - BranchShortUrlRequest *shortURLObject = [BranchShortUrlRequest new]; - [_queue enqueue: shortURLObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchShortUrlRequest.class]) { - XCTAssertTrue([shortURLObject.requestUUID isEqualToString:((BranchShortUrlRequest *)requestObject).requestUUID]); - XCTAssertTrue([shortURLObject.requestCreationTimeStamp isEqualToNumber:((BranchShortUrlRequest *)requestObject).requestCreationTimeStamp]); - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForShortURLWithParams { - - BranchShortUrlRequest *shortURLObject = [[BranchShortUrlRequest alloc] initWithTags:nil alias:nil type:BranchLinkTypeUnlimitedUse matchDuration:0 channel:nil feature:nil stage:nil campaign:nil params:nil linkData:nil linkCache:nil callback:^(NSString * _Nullable url, NSError * _Nullable error) {}]; - [_queue enqueue: shortURLObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchShortUrlRequest.class]) { - XCTAssertTrue([shortURLObject.requestUUID isEqualToString:((BranchShortUrlRequest *)requestObject).requestUUID]); - XCTAssertTrue([shortURLObject.requestCreationTimeStamp isEqualToNumber:((BranchShortUrlRequest *)requestObject).requestCreationTimeStamp]); - } else { - XCTFail("Invalid Object type found"); - } - } -} - -- (void)testUUIDANDTimeStampPersistenceForLATD { - - BranchLATDRequest *latdObject = [BranchLATDRequest new]; - [_queue enqueue: latdObject]; - [_queue persistImmediately]; - - NSArray *decodedQueue = [self getQueueCachedOnDisk]; - - for (id requestObject in decodedQueue) { - if ([requestObject isKindOfClass:BranchLATDRequest.class]) { - XCTAssertTrue([latdObject.requestUUID isEqualToString:((BranchLATDRequest *)requestObject).requestUUID]); - XCTAssertTrue([latdObject.requestCreationTimeStamp isEqualToNumber:((BranchLATDRequest *)requestObject).requestCreationTimeStamp]); - } else { - XCTFail("Invalid Object type found"); - } - } -} - - -@end diff --git a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj index 23e32a6c7..ef254bdf8 100644 --- a/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj +++ b/Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj @@ -188,7 +188,6 @@ 5F644C492B7AA811000DCD78 /* BNCEventUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F644BB82B7AA811000DCD78 /* BNCEventUtils.m */; }; 5F67F48E228F535500067429 /* BNCEncodingUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F67F48D228F535500067429 /* BNCEncodingUtilsTests.m */; }; 5F6D86D92BB5E9650068B536 /* BNCClassSerializationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F6D86D82BB5E9650068B536 /* BNCClassSerializationTests.m */; }; - 5F83B9ED2433BAAA0054A022 /* BNCServerInterface.Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D16837E2098C901008819E3 /* BNCServerInterface.Test.m */; }; 5F86501A2B76DA3200364BDE /* NSMutableDictionaryBranchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F8650192B76DA3200364BDE /* NSMutableDictionaryBranchTests.m */; }; 5F892EC5236116CD0023AEC1 /* NSErrorBranchTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F892EC4236116CC0023AEC1 /* NSErrorBranchTests.m */; }; 5F8B7B4021B5F5CD009CE0A6 /* libBranch.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 466B58381B17773000A69EDE /* libBranch.a */; }; @@ -200,7 +199,6 @@ 5F92B2362383644C00CA909B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F92B2352383644C00CA909B /* SystemConfiguration.framework */; }; 5F92B242238752A500CA909B /* BNCDeviceInfoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F92B241238752A500CA909B /* BNCDeviceInfoTests.m */; }; 5FA9112F29BC662000F3D35C /* BNCNetworkInterfaceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5FA9112E29BC662000F3D35C /* BNCNetworkInterfaceTests.m */; }; - 5FB6CC13264F0C7C0020E478 /* BNCServerRequestQueueTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5FB6CC12264F0C7C0020E478 /* BNCServerRequestQueueTests.m */; }; 5FC20E732A93D85F00D9E1C8 /* BNCRequestFactoryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5FC20E722A93D85F00D9E1C8 /* BNCRequestFactoryTests.m */; }; 5FC4CF8C24860C440001E701 /* latd.json in Resources */ = {isa = PBXBuildFile; fileRef = 5FC4CF7E24860C320001E701 /* latd.json */; }; 5FC4CF8D24860C440001E701 /* latd_missing_window.json in Resources */ = {isa = PBXBuildFile; fileRef = 5FC4CF7F24860C320001E701 /* latd_missing_window.json */; }; @@ -490,7 +488,6 @@ 5F92B2352383644C00CA909B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; }; 5F92B241238752A500CA909B /* BNCDeviceInfoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCDeviceInfoTests.m; sourceTree = ""; }; 5FA9112E29BC662000F3D35C /* BNCNetworkInterfaceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCNetworkInterfaceTests.m; sourceTree = ""; }; - 5FB6CC12264F0C7C0020E478 /* BNCServerRequestQueueTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCServerRequestQueueTests.m; sourceTree = ""; }; 5FC20E722A93D85F00D9E1C8 /* BNCRequestFactoryTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCRequestFactoryTests.m; sourceTree = ""; }; 5FC4CF7E24860C320001E701 /* latd.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = latd.json; sourceTree = ""; }; 5FC4CF7F24860C320001E701 /* latd_missing_window.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = latd_missing_window.json; sourceTree = ""; }; @@ -629,7 +626,6 @@ 5F92B23323835FEB00CA909B /* BNCReachabilityTests.m */, C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */, 5FC20E722A93D85F00D9E1C8 /* BNCRequestFactoryTests.m */, - 5FB6CC12264F0C7C0020E478 /* BNCServerRequestQueueTests.m */, 5FDB04F324E6156800F2F267 /* BNCSKAdNetworkTests.m */, 4D16838F2098C901008819E3 /* BNCSystemObserverTests.m */, 5FCF7EAC29DC96A7008D629E /* BNCURLFilterSkiplistUpgradeTests.m */, @@ -1386,7 +1382,6 @@ C1CC888229BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m in Sources */, 5FE694382405FA2700E3AEE2 /* BNCCallbackMapTests.m in Sources */, 5FDB04F424E6156800F2F267 /* BNCSKAdNetworkTests.m in Sources */, - 5FB6CC13264F0C7C0020E478 /* BNCServerRequestQueueTests.m in Sources */, 4D1683AE2098C902008819E3 /* BNCLinkDataTests.m in Sources */, C15CC9E02ABCF8C8003CC339 /* BranchActivityItemTests.m in Sources */, 5F92B23423835FEB00CA909B /* BNCReachabilityTests.m in Sources */, diff --git a/BranchSDK.podspec b/BranchSDK.podspec index 992acfaf1..e93954983 100644 --- a/BranchSDK.podspec +++ b/BranchSDK.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "BranchSDK" - s.version = "3.6.4" + s.version = "3.6.5" 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 7219bec79..4472d5212 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.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2009,7 +2009,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2215,7 +2215,7 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.6.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2254,7 +2254,7 @@ "@loader_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 3.6.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2291,7 +2291,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, @@ -2326,7 +2326,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 3.6.4; + MARKETING_VERSION = 3.6.5; OTHER_LDFLAGS = ( "-weak_framework", LinkPresentation, diff --git a/ChangeLog.md b/ChangeLog.md index e18e5141c..8996557c5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ Branch iOS SDK Change Log +v.3.6.5 +- Removed on-disk caching and replay of server request objects. + v.3.6.4 - Added 'branch_sdk_request_unique_id' and 'branch_sdk_request_timestamp' to post params of all the SDK requests. diff --git a/Sources/BranchSDK/BNCConfig.m b/Sources/BranchSDK/BNCConfig.m index a2c0f2342..47cd61fdd 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.4"; +NSString * const BNC_SDK_VERSION = @"3.6.5"; NSString * const BNC_LINK_URL = @"https://bnc.lt"; NSString * const BNC_CDN_URL = @"https://cdn.branch.io"; diff --git a/Sources/BranchSDK/BNCServerRequestQueue.m b/Sources/BranchSDK/BNCServerRequestQueue.m index 2147f0fe8..c518fccce 100755 --- a/Sources/BranchSDK/BNCServerRequestQueue.m +++ b/Sources/BranchSDK/BNCServerRequestQueue.m @@ -17,20 +17,8 @@ #import "BranchLogger.h" - -static NSString * const BRANCH_QUEUE_FILE = @"BNCServerRequestQueue"; -static NSTimeInterval const BATCH_WRITE_TIMEOUT = 3.0; - - -static inline uint64_t BNCNanoSecondsFromTimeInterval(NSTimeInterval interval) { - return interval * ((NSTimeInterval) NSEC_PER_SEC); -} - - @interface BNCServerRequestQueue() @property (strong, nonatomic) NSMutableArray *queue; -@property (strong, nonatomic) dispatch_queue_t asyncQueue; -@property (strong, nonatomic) dispatch_source_t persistTimer; @end @@ -41,27 +29,13 @@ - (instancetype)init { if (!self) return self; self.queue = [NSMutableArray new]; - self.asyncQueue = dispatch_queue_create("io.branch.persist_queue", DISPATCH_QUEUE_SERIAL); - self.processArchivedOpens = YES; return self; } -- (void)dealloc { - @synchronized (self) { - if (self.persistTimer) { - dispatch_source_cancel(self.persistTimer); - self.persistTimer = nil; - } - [self persistImmediately]; - self.queue = nil; - } -} - - (void)enqueue:(BNCServerRequest *)request { @synchronized (self) { if (request) { [self.queue addObject:request]; - [self persistEventually]; } } } @@ -74,7 +48,6 @@ - (void)insert:(BNCServerRequest *)request at:(NSUInteger)index { } if (request) { [self.queue insertObject:request atIndex:index]; - [self persistEventually]; } } } @@ -85,7 +58,6 @@ - (BNCServerRequest *)dequeue { if (self.queue.count > 0) { request = [self.queue objectAtIndex:0]; [self.queue removeObjectAtIndex:0]; - [self persistEventually]; } return request; } @@ -100,7 +72,6 @@ - (BNCServerRequest *)removeAt:(NSUInteger)index { } request = [self.queue objectAtIndex:index]; [self.queue removeObjectAtIndex:index]; - [self persistEventually]; return request; } } @@ -108,7 +79,6 @@ - (BNCServerRequest *)removeAt:(NSUInteger)index { - (void)remove:(BNCServerRequest *)request { @synchronized (self) { [self.queue removeObject:request]; - [self persistEventually]; } } @@ -145,7 +115,6 @@ - (NSString *)description { - (void)clearQueue { @synchronized (self) { [self.queue removeAllObjects]; - [self persistImmediately]; } } @@ -177,226 +146,12 @@ - (BranchOpenRequest *)findExistingInstallOrOpen { } } -#pragma mark - Private Methods - -- (void)persistEventually { - @synchronized (self) { - if (self.persistTimer) return; - - self.persistTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, self.asyncQueue); - if (!self.persistTimer) return; - - dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, BNCNanoSecondsFromTimeInterval(BATCH_WRITE_TIMEOUT)); - dispatch_source_set_timer( - self.persistTimer, - startTime, - BNCNanoSecondsFromTimeInterval(BATCH_WRITE_TIMEOUT), - BNCNanoSecondsFromTimeInterval(BATCH_WRITE_TIMEOUT / 10.0) - ); - __weak __typeof(self) weakSelf = self; - dispatch_source_set_event_handler(self.persistTimer, ^ { - __strong __typeof(weakSelf) strongSelf = weakSelf; - if (strongSelf) { - [strongSelf cancelTimer]; - [strongSelf persistImmediately]; - } - }); - dispatch_resume(self.persistTimer); - } -} - -- (void)cancelTimer { - @synchronized (self) { - if (self.persistTimer) { - dispatch_source_cancel(self.persistTimer); - self.persistTimer = nil; - } - } -} - -- (void)persistImmediately { - @synchronized (self) { - if (!self.queue || self.queue.count == 0) { - return; - } - NSArray *queueCopy = [self.queue copy]; - - // encode the list of encoded request objects - NSData *data = [self archiveQueue:queueCopy]; - if (data) { - NSError *error = nil; - [data writeToURL:self.class.URLForQueueFile options:NSDataWritingAtomic error:&error]; - - if (error) { - [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to persist queue to disk: %@.", error] error:error]; - } - } else { - [[BranchLogger shared] logError:[NSString stringWithFormat:@"Failed to encode queue."] error:nil]; - } - } -} - -// assumes queue no longer mutable -- (NSData *)archiveQueue:(NSArray *)queue { - NSMutableArray *archivedRequests = [NSMutableArray new]; - NSSet *requestClasses = [BNCServerRequestQueue replayableRequestClasses]; - for (BNCServerRequest *request in queue) { - - // only persist analytics requests, skip the rest - if ([requestClasses containsObject:request.class]) { - [archivedRequests addObject:request]; - } - } - return [self archiveObject:archivedRequests]; -} - -// For testing backwards compatibility -// The old version did a double archive and didn't filter replayable requests -- (NSData *)oldArchiveQueue:(NSArray *)queue { - NSMutableArray *archivedRequests = [NSMutableArray new]; - for (BNCServerRequest *request in queue) { - - // archive every request - NSData *encodedRequest = [self archiveObject:request]; - [archivedRequests addObject:encodedRequest]; - } - return [self archiveObject:archivedRequests]; -} - -- (NSData *)archiveObject:(NSObject *)object { - NSData *data = nil; - NSError *error = nil; - data = [NSKeyedArchiver archivedDataWithRootObject:object requiringSecureCoding:YES error:&error]; - - if (!data && error) { - [[BranchLogger shared] logWarning:@"Failed to archive: %@" error:error]; - } - return data; -} - -// Loads saved requests from disk. Only called on app start. -- (void)retrieve { - @synchronized (self) { - NSError *error = nil; - NSData *data = [NSData dataWithContentsOfURL:self.class.URLForQueueFile options:0 error:&error]; - if (!error && data) { - NSMutableArray *decodedQueue = [self unarchiveQueueFromData:data]; - for (id request in decodedQueue) { - if ([request isKindOfClass:[BranchOpenRequest class]] || [request isKindOfClass:[BranchInstallRequest class]]) { - ((BranchOpenRequest *)request).isFromArchivedQueue = YES; - } - } - self.queue = decodedQueue; - // Requests are loaded into queue now. Delete queue file stored on disk. - [self removeSaveFile]; - } - } -} - -// 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) { - NSError *error; - [NSFileManager.defaultManager removeItemAtURL:fileURL error:&error]; - - if (error) { - [[BranchLogger shared] logError:@"Failed to remove archived queue" error:error]; - } - } -} - -- (NSMutableArray *)unarchiveQueueFromData:(NSData *)data { - NSMutableArray *queue = [NSMutableArray new]; - - NSArray *requestArray = nil; - id tmp = [self unarchiveObjectFromData:data]; - if ([tmp isKindOfClass:[NSArray class]]) { - requestArray = (NSArray *)tmp; - } - - // validate request array - // There should never be an object that is not a replayable class or NSData - for (id request in requestArray) { - id tmpRequest = request; - - // handle legacy NSData - if ([request isKindOfClass:[NSData class]]) { - tmpRequest = [self unarchiveObjectFromData:request]; - } - - // make sure we didn't unarchive something unexpected - if ([[BNCServerRequestQueue replayableRequestClasses] containsObject:[tmpRequest class]]) { - [queue addObject:tmpRequest]; - } - } - - return queue; -} - -- (id)unarchiveObjectFromData:(NSData *)data { - NSError *error; - id object = [NSKeyedUnarchiver unarchivedObjectOfClasses:[BNCServerRequestQueue encodableClasses] fromData:data error:&error]; - - if (error) { - [[BranchLogger shared] logError:@"Failed to unarchive" error:error]; - [self removeSaveFile]; - } - - return object; -} - -// only replay analytics requests, the others are time sensitive -+ (NSSet *)replayableRequestClasses { - static NSSet *requestClasses = nil; - static dispatch_once_t onceToken = 0; - dispatch_once(&onceToken, ^ { - NSArray *tmp = @[ - [BranchOpenRequest class], - [BranchInstallRequest class], - [BranchEventRequest class] - ]; - requestClasses = [NSSet setWithArray:tmp]; - }); - - return requestClasses; -} - -// encodable classes also includes NSArray and NSData -+ (NSSet *)encodableClasses { - static NSSet *classes = nil; - static dispatch_once_t onceToken = 0; - dispatch_once(&onceToken, ^ { - NSMutableArray *tmp = [NSMutableArray new]; - [tmp addObject:[NSArray class]]; // root object - [tmp addObject:[NSData class]]; // legacy format compatibility - - // add all replayable request objects - [tmp addObjectsFromArray: [[BNCServerRequestQueue replayableRequestClasses] allObjects]]; - - classes = [NSSet setWithArray:tmp]; - }); - - return classes; -} - -+ (NSURL * _Nonnull) URLForQueueFile { - static NSURL *URL = nil; - static dispatch_once_t onceToken = 0; - dispatch_once(&onceToken, ^ { - URL = BNCURLForBranchDirectory(); - URL = [URL URLByAppendingPathComponent:BRANCH_QUEUE_FILE isDirectory:NO]; - }); - return URL; -} + (instancetype)getInstance { static BNCServerRequestQueue *sharedQueue = nil; static dispatch_once_t onceToken = 0; dispatch_once(&onceToken, ^ { sharedQueue = [[BNCServerRequestQueue alloc] init]; - [sharedQueue retrieve]; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Retrieved from storage: %@.", sharedQueue] error:nil]; }); return sharedQueue; } diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 9b4d4f87e..25433f7eb 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -1739,8 +1739,6 @@ - (void)applicationWillResignActive { if (!Branch.trackingDisabled) { self.initializationStatus = BNCInitStatusUninitialized; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationWillResignActive initializationStatus %ld", self.initializationStatus] error:nil]; - - [self.requestQueue persistImmediately]; [BranchOpenRequest setWaitNeededForOpenResponseLock]; } }); @@ -1897,16 +1895,6 @@ - (void)processNextQueueItem { } } - if ( !(((BNCServerRequestQueue*)[BNCServerRequestQueue getInstance]).processArchivedOpens) - && [req isKindOfClass:[BranchOpenRequest class]] - && ((BranchOpenRequest *)req).isFromArchivedQueue){ - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Removed Archived Open Request from Queue %@", [req description]] error:nil]; - [self.requestQueue remove:req]; - self.networkCount = 0; - [self processNextQueueItem]; - return; - } - dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^ { [req makeRequest:self.serverInterface key:self.class.branchKey callback: diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index a05c5bf47..9bd10f806 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -152,10 +152,6 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { } } } - - if (referringURL.length > 0) { - ((BNCServerRequestQueue *)[BNCServerRequestQueue getInstance]).processArchivedOpens = NO; - } // Clear link identifiers so they don't get reused on the next open preferenceHelper.linkClickIdentifier = nil; diff --git a/Sources/BranchSDK/Public/BNCServerRequestQueue.h b/Sources/BranchSDK/Public/BNCServerRequestQueue.h index 311c65a76..1c9d9391f 100755 --- a/Sources/BranchSDK/Public/BNCServerRequestQueue.h +++ b/Sources/BranchSDK/Public/BNCServerRequestQueue.h @@ -11,8 +11,6 @@ @interface BNCServerRequestQueue : NSObject -@property (assign, nonatomic) BOOL processArchivedOpens; - - (void)enqueue:(BNCServerRequest *)request; - (BNCServerRequest *)dequeue; - (BNCServerRequest *)peek; @@ -27,8 +25,5 @@ - (BranchOpenRequest *)findExistingInstallOrOpen; -- (void)persistEventually; -- (void)persistImmediately; - + (id)getInstance; @end diff --git a/scripts/version.sh b/scripts/version.sh index f1ba477db..f83d5093d 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -30,7 +30,7 @@ Options: USAGE } -version=3.6.4 +version=3.6.5 prev_version="$version" if (( $# == 0 )); then