Skip to content

Commit 432f2cb

Browse files
authored
Share always reports completed even when cancelled (AIS-395). (#736)
* Fixed logic change.
1 parent d1c5102 commit 432f2cb

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Branch-SDK/Branch-SDK/BranchShareLink.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error {
7979
if ([self.delegate respondsToSelector:@selector(branchShareLink:didComplete:withError:)]) {
8080
[self.delegate branchShareLink:self didComplete:completed withError:error];
8181
}
82-
[self.universalObject userCompletedAction:BNCShareCompletedEvent];
82+
if (completed && !error)
83+
[self.universalObject userCompletedAction:BNCShareCompletedEvent];
8384
NSDictionary *attributes = [self.universalObject getDictionaryWithCompleteLinkProperties:self.linkProperties];
8485
[BNCFabricAnswers sendEventWithName:@"Branch Share" andAttributes:attributes];
8586
}

Branch-SDK/Branch-SDK/BranchUniversalObject.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,21 @@ - (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
257257
if ([shareViewController respondsToSelector:@selector(completionWithItemsHandler)]) {
258258
shareViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
259259
// Log share completed event
260-
[self userCompletedAction:BNCShareCompletedEvent];
261-
if (completion || completionError) {
262-
if (completion) { completion(activityType, completed); }
263-
else if (completionError) { completionError(activityType, completed, activityError); }
264-
[BNCFabricAnswers sendEventWithName:@"Branch Share" andAttributes:[self getDictionaryWithCompleteLinkProperties:linkProperties]];
265-
}
260+
if (completed && !activityError)
261+
[self userCompletedAction:BNCShareCompletedEvent];
262+
if (completion)
263+
completion(activityType, completed);
264+
else
265+
if (completionError)
266+
completionError(activityType, completed, activityError);
267+
[BNCFabricAnswers sendEventWithName:@"Branch Share" andAttributes:[self getDictionaryWithCompleteLinkProperties:linkProperties]];
266268
};
267269
} else {
268-
#pragma clang diagnostic push
269-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
270+
#pragma clang diagnostic push
271+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
270272
// Deprecated in iOS 8. Safe to hide deprecation warnings as the new completion handler is checked for above
271273
shareViewController.completionHandler = completion;
272-
#pragma clang diagnostic pop
274+
#pragma clang diagnostic pop
273275
}
274276

275277
UIViewController *presentingViewController;
@@ -278,7 +280,8 @@ - (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
278280
}
279281
else {
280282
Class UIApplicationClass = NSClassFromString(@"UIApplication");
281-
if ([[[[UIApplicationClass sharedApplication].delegate window] rootViewController] respondsToSelector:@selector(presentViewController:animated:completion:)]) {
283+
if ([[[[UIApplicationClass sharedApplication].delegate window] rootViewController]
284+
respondsToSelector:@selector(presentViewController:animated:completion:)]) {
282285
presentingViewController = [[[UIApplicationClass sharedApplication].delegate window] rootViewController];
283286
}
284287
}

0 commit comments

Comments
 (0)