Skip to content

Commit

Permalink
Remove share link and share sheet callbacks that do not have an NSError
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-branch committed Nov 2, 2023
1 parent 6c171f7 commit 7debbd3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 61 deletions.
1 change: 0 additions & 1 deletion BranchSDK/BranchShareLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ Presents a UIActivityViewController that shares the Branch link.
///The delegate. See 'BranchShareLinkDelegate' above for a description.
@property (nonatomic, weak) id<BranchShareLinkDelegate>_Nullable delegate;

@property void (^ _Nullable completion)(NSString * _Nullable activityType, BOOL completed);
@property void (^ _Nullable completionError)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error);

/**
Expand Down
17 changes: 5 additions & 12 deletions BranchSDK/BranchShareLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error {
if (completed && !error) {
[[BranchEvent customEventWithName:BNCShareCompletedEvent contentItem:self.universalObject] logEvent];
}
if (self.completion)
self.completion(self.activityType, completed);
else
if (self.completionError)
self.completionError(self.activityType, completed, error);
if (self.completionError) {
self.completionError(self.activityType, completed, error);
}
}

- (NSArray<UIActivityItemProvider*>*_Nonnull) activityItems {
Expand All @@ -116,19 +114,14 @@ - (void) shareDidComplete:(BOOL)completed activityError:(NSError*)error {
}

// Make sure we can share

if (!(self.universalObject.canonicalIdentifier ||
self.universalObject.canonicalUrl ||
self.universalObject.title)) {
if (!(self.universalObject.canonicalIdentifier || self.universalObject.canonicalUrl || self.universalObject.title)) {
BNCLogWarning(@"A canonicalIdentifier, canonicalURL, or title are required to uniquely"
" identify content. In order to not break the end user experience with sharing,"
" Branch SDK will proceed to create a URL, but content analytics may not properly"
" include this URL.");
}

self.serverParameters =
[[self.universalObject getParamsForServerRequestWithAddedLinkProperties:self.linkProperties]
mutableCopy];
self.serverParameters = [[self.universalObject getParamsForServerRequestWithAddedLinkProperties:self.linkProperties] mutableCopy];
if (self.linkProperties.matchDuration) {
self.serverParameters[BRANCH_REQUEST_KEY_URL_DURATION] = @(self.linkProperties.matchDuration);
}
Expand Down
4 changes: 1 addition & 3 deletions BranchSDK/BranchUniversalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,19 @@ FOUNDATION_EXPORT BranchCondition _Nonnull BranchConditionRefurbished;
#if !TARGET_OS_TV

- (void)showShareSheetWithShareText:(nullable NSString *)shareText
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion;
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion;

- (void)showShareSheetWithLinkProperties:(nullable BranchLinkProperties *)linkProperties
andShareText:(nullable NSString *)shareText
fromViewController:(nullable UIViewController *)viewController
completionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion;

// iPad needs an anchor
- (void)showShareSheetWithLinkProperties:(nullable BranchLinkProperties *)linkProperties
andShareText:(nullable NSString *)shareText
fromViewController:(nullable UIViewController *)viewController
anchor:(nullable UIBarButtonItem *)anchor
completionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion;


/// @name List items on Spotlight


Expand Down
58 changes: 13 additions & 45 deletions BranchSDK/BranchUniversalObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -392,55 +392,26 @@ - (NSString *)getLongUrlWithChannel:(NSString *)channel
#if !TARGET_OS_TV

- (void)showShareSheetWithShareText:(NSString *)shareText
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion {
[self showShareSheetWithLinkProperties:nil andShareText:shareText fromViewController:nil completion:completion];
}

- (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
andShareText:(NSString *)shareText
fromViewController:(UIViewController *)viewController
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion {
[self showShareSheetWithLinkProperties:linkProperties andShareText:shareText
fromViewController:viewController anchor:nil completion:completion orCompletionWithError:nil];
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion {
[self showShareSheetWithLinkProperties:nil andShareText:shareText fromViewController:nil completionWithError:completion];
}

- (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
andShareText:(NSString *)shareText
fromViewController:(UIViewController *)viewController
completionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion {
[self showShareSheetWithLinkProperties:linkProperties andShareText:shareText
fromViewController:viewController anchor:nil completion:nil orCompletionWithError:completion];
}

- (void)showShareSheetWithLinkProperties:(nullable BranchLinkProperties *)linkProperties
andShareText:(nullable NSString *)shareText
fromViewController:(nullable UIViewController *)viewController
anchor:(nullable id)anchor
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion {
[self showShareSheetWithLinkProperties:linkProperties andShareText:shareText
fromViewController:viewController anchor:anchor completion:completion orCompletionWithError:nil];
}

- (void)showShareSheetWithLinkProperties:(nullable BranchLinkProperties *)linkProperties
andShareText:(nullable NSString *)shareText
fromViewController:(nullable UIViewController *)viewController
anchor:(nullable id)anchor
completionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion {
[self showShareSheetWithLinkProperties:linkProperties andShareText:shareText
fromViewController:viewController anchor:anchor completion:nil orCompletionWithError:completion];
[self showShareSheetWithLinkProperties:linkProperties andShareText:shareText fromViewController:viewController anchor:nil completionWithError:completion];
}

- (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
andShareText:(NSString *)shareText
fromViewController:(UIViewController *)viewController
anchor:(nullable id)anchorViewOrButtonItem
completion:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion
orCompletionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completionError {
completionWithError:(void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError*_Nullable error))completion {

BranchShareLink *shareLink = [[BranchShareLink alloc] initWithUniversalObject:self linkProperties:linkProperties];
shareLink.shareText = shareText;
shareLink.completion = completion;
shareLink.completionError = completionError;
shareLink.completionError = completion;
[shareLink presentActivityViewControllerFromViewController:viewController anchor:anchorViewOrButtonItem];
}

Expand All @@ -464,8 +435,7 @@ - (void)listOnSpotlightWithIdentifierCallback:(callbackWithUrlAndSpotlightIdenti
BOOL publiclyIndexable;
if (self.contentIndexMode == BranchContentIndexModePrivate) {
publiclyIndexable = NO;
}
else {
} else {
publiclyIndexable = YES;
}

Expand Down Expand Up @@ -500,17 +470,15 @@ - (void)listOnSpotlightWithLinkProperties:(BranchLinkProperties*_Nullable)linkpr
}];
}

- (void) removeFromSpotlightWithCallback:(void (^_Nullable)(NSError * _Nullable error))completion{
- (void)removeFromSpotlightWithCallback:(void (^_Nullable)(NSError * _Nullable error))completion {
if (self.locallyIndex) {
[[Branch getInstance] removeSearchableItemWithBranchUniversalObject:self
callback:^(NSError *error) {
if (completion) {
completion(error);
}
}];
[[Branch getInstance] removeSearchableItemWithBranchUniversalObject:self callback:^(NSError *error) {
if (completion) {
completion(error);
}
}];
} else {
NSError *error = [NSError branchErrorWithCode:BNCSpotlightPublicIndexError
localizedMessage:@"Publically indexed cannot be removed from Spotlight"];
NSError *error = [NSError branchErrorWithCode:BNCSpotlightPublicIndexError localizedMessage:@"Publically indexed cannot be removed from Spotlight"];
if (completion) completion(error);
}
}
Expand Down

0 comments on commit 7debbd3

Please sign in to comment.