Skip to content

Commit 9d847ed

Browse files
authored
Merge pull request #960 from BranchMetrics/SDK-631-handle-init-error-states
SDK-631 add workaround for error state handling
2 parents ce3f3c1 + 81faded commit 9d847ed

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,8 @@ - (void)setIdentity:(NSString *)userId withCallback:(callbackWithParams)callback
958958
}
959959
return;
960960
}
961+
962+
[self initSafetyCheck];
961963
dispatch_async(self.isolationQueue, ^(){
962964
BranchSetIdentityRequest *req = [[BranchSetIdentityRequest alloc] initWithUserId:userId callback:callback];
963965
[self.requestQueue enqueue:req];
@@ -1015,6 +1017,8 @@ - (void)userCompletedAction:(NSString *)action withState:(NSDictionary *)state {
10151017
if (!action) {
10161018
return;
10171019
}
1020+
1021+
[self initSafetyCheck];
10181022
dispatch_async(self.isolationQueue, ^(){
10191023
BranchUserCompletedActionRequest *req = [[BranchUserCompletedActionRequest alloc] initWithAction:action state:state];
10201024
[self.requestQueue enqueue:req];
@@ -1027,6 +1031,7 @@ - (void)userCompletedAction:(NSString *)action withState:(NSDictionary *)state w
10271031
}
10281032

10291033
- (void)sendServerRequest:(BNCServerRequest*)request {
1034+
[self initSafetyCheck];
10301035
dispatch_async(self.isolationQueue, ^(){
10311036
[self.requestQueue enqueue:request];
10321037
[self processNextQueueItem];
@@ -1039,6 +1044,7 @@ - (void)sendServerRequestWithoutSession:(BNCServerRequest*)request {
10391044
}
10401045

10411046
- (void)sendCommerceEvent:(BNCCommerceEvent *)commerceEvent metadata:(NSDictionary*)metadata withCompletion:(void (^)(NSDictionary *, NSError *))completion {
1047+
[self initSafetyCheck];
10421048
dispatch_async(self.isolationQueue, ^(){
10431049
BranchCommerceEventRequest *request = [[BranchCommerceEventRequest alloc] initWithCommerceEvent:commerceEvent metadata:metadata completion:completion];
10441050
[self.requestQueue enqueue:request];
@@ -1049,6 +1055,7 @@ - (void)sendCommerceEvent:(BNCCommerceEvent *)commerceEvent metadata:(NSDictiona
10491055
#pragma mark - Credit methods
10501056

10511057
- (void)loadRewardsWithCallback:(callbackWithStatus)callback {
1058+
[self initSafetyCheck];
10521059
dispatch_async(self.isolationQueue, ^(){
10531060
BranchLoadRewardsRequest *req = [[BranchLoadRewardsRequest alloc] initWithCallback:callback];
10541061
[self.requestQueue enqueue:req];
@@ -1097,7 +1104,7 @@ - (void)redeemRewards:(NSInteger)count forBucket:(NSString *)bucket callback:(ca
10971104
}
10981105
return;
10991106
}
1100-
1107+
[self initSafetyCheck];
11011108
dispatch_async(self.isolationQueue, ^(){
11021109
BranchRedeemRewardsRequest *req = [[BranchRedeemRewardsRequest alloc] initWithAmount:count bucket:bucket callback:callback];
11031110
[self.requestQueue enqueue:req];
@@ -1118,6 +1125,7 @@ - (void)getCreditHistoryAfter:(NSString *)creditTransactionId number:(NSInteger)
11181125
}
11191126

11201127
- (void)getCreditHistoryForBucket:(NSString *)bucket after:(NSString *)creditTransactionId number:(NSInteger)length order:(BranchCreditHistoryOrder)order andCallback:(callbackWithList)callback {
1128+
[self initSafetyCheck];
11211129
dispatch_async(self.isolationQueue, ^(){
11221130
BranchCreditHistoryRequest *req = [[BranchCreditHistoryRequest alloc] initWithBucket:bucket creditTransactionId:creditTransactionId length:length order:order callback:callback];
11231131
[self.requestQueue enqueue:req];
@@ -1317,6 +1325,7 @@ - (void)getShortUrlWithParams:(NSDictionary *)params andTags:(NSArray *)tags and
13171325
}
13181326

13191327
- (void)getSpotlightUrlWithParams:(NSDictionary *)params callback:(callbackWithParams)callback {
1328+
[self initSafetyCheck];
13201329
dispatch_async(self.isolationQueue, ^(){
13211330
BranchSpotlightUrlRequest *req = [[BranchSpotlightUrlRequest alloc] initWithParams:params callback:callback];
13221331
[self.requestQueue enqueue:req];
@@ -1550,6 +1559,8 @@ - (void)generateShortUrl:(NSArray *)tags
15501559
andStage:(NSString *)stage
15511560
andCampaign:campaign andParams:(NSDictionary *)params
15521561
andCallback:(callbackWithUrl)callback {
1562+
1563+
[self initSafetyCheck];
15531564
dispatch_async(self.isolationQueue, ^(){
15541565
BNCLinkData *linkData = [self prepareLinkDataFor:tags
15551566
andAlias:alias
@@ -1742,6 +1753,7 @@ - (BNCLinkData *)prepareLinkDataFor:(NSArray *)tags
17421753
#pragma mark - BranchUniversalObject methods
17431754

17441755
- (void)registerViewWithParams:(NSDictionary *)params andCallback:(callbackWithParams)callback {
1756+
[self initSafetyCheck];
17451757
dispatch_async(self.isolationQueue, ^(){
17461758
BranchUniversalObject *buo = [[BranchUniversalObject alloc] init];
17471759
buo.contentMetadata.customMetadata = (id) params;
@@ -1932,6 +1944,16 @@ - (void)clearNetworkQueue {
19321944

19331945
#pragma mark - Session Initialization
19341946

1947+
// SDK-631 Workaround to maintain existing error handling behavior.
1948+
// Some methods require init before they are called. Instead of returning an error, we try to fix the situation by calling init ourselves.
1949+
// There is a follow up ticket to improve this. SDK-633
1950+
- (void)initSafetyCheck {
1951+
if (self.initializationStatus == BNCInitStatusUninitialized) {
1952+
BNCLogWarning(@"Branch avoided an error by preemptively initializing.");
1953+
[self initUserSessionAndCallCallback:NO];
1954+
}
1955+
}
1956+
19351957
- (void)initUserSessionAndCallCallback:(BOOL)callCallback {
19361958
dispatch_async(self.isolationQueue, ^(){
19371959
NSString *urlstring = nil;

0 commit comments

Comments
 (0)