@@ -413,26 +413,6 @@ - (NSString *)getLongUrlWithChannel:(NSString *)channel
413
413
#pragma mark - Share Sheets
414
414
#if !TARGET_OS_TV
415
415
416
- - (UIActivityItemProvider *)getBranchActivityItemWithLinkProperties : (BranchLinkProperties *)linkProperties {
417
- if (!self.canonicalIdentifier && !self.canonicalUrl && !self.title ) {
418
- BNCLogWarning (@" A canonicalIdentifier, canonicalURL, or title are required to uniquely identify content. "
419
- " In order to not break the end user experience with sharing, Branch SDK will proceed to create a URL, "
420
- " but content analytics may not properly include this URL." );
421
- }
422
-
423
- NSMutableDictionary *params = [[self getParamsForServerRequestWithAddedLinkProperties: linkProperties] mutableCopy ];
424
- if (linkProperties.matchDuration ) {
425
- [params setObject: @(linkProperties.matchDuration) forKey: BRANCH_REQUEST_KEY_URL_DURATION];
426
- }
427
-
428
- return [Branch getBranchActivityItemWithParams: params
429
- feature: linkProperties.feature
430
- stage: linkProperties.stage
431
- campaign: linkProperties.campaign
432
- tags: linkProperties.tags
433
- alias: linkProperties.alias];
434
- }
435
-
436
416
- (void )showShareSheetWithShareText : (NSString *)shareText
437
417
completion : (void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion {
438
418
[self showShareSheetWithLinkProperties: nil andShareText: shareText fromViewController: nil completion: completion];
@@ -478,79 +458,12 @@ - (void)showShareSheetWithLinkProperties:(BranchLinkProperties *)linkProperties
478
458
anchor : (nullable id )anchorViewOrButtonItem
479
459
completion : (void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed))completion
480
460
orCompletionWithError : (void (^ _Nullable)(NSString * _Nullable activityType, BOOL completed, NSError *_Nullable error))completionError {
481
-
482
- // Log share initiated event
483
- [[BranchEvent customEventWithName: BNCShareInitiatedEvent contentItem: self ] logEvent ];
484
- UIActivityItemProvider *itemProvider = [self getBranchActivityItemWithLinkProperties: linkProperties];
485
- NSMutableArray *items = [NSMutableArray arrayWithObject: itemProvider];
486
- if (shareText) {
487
- [items insertObject: shareText atIndex: 0 ];
488
- }
489
- UIActivityViewController *shareViewController =
490
- [[UIActivityViewController alloc ] initWithActivityItems: items applicationActivities: nil ];
491
-
492
- if ([shareViewController respondsToSelector: @selector (completionWithItemsHandler )]) {
493
- shareViewController.completionWithItemsHandler =
494
- ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
495
- // Log share completed event
496
- if (completed && !activityError) {
497
- [[BranchEvent customEventWithName: BNCShareCompletedEvent contentItem: self ] logEvent ];
498
- }
499
- if (completion)
500
- completion (activityType, completed);
501
- else
502
- if (completionError)
503
- completionError (activityType, completed, activityError);
504
- };
505
- } else {
506
- #pragma clang diagnostic push
507
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
508
- // Deprecated in iOS 8. Safe to hide deprecation warnings as the new completion handler is checked for above
509
- shareViewController.completionHandler = completion;
510
- #pragma clang diagnostic pop
511
- }
512
-
513
- UIViewController *presentingViewController = nil ;
514
- if (viewController && [viewController respondsToSelector: @selector (presentViewController:animated:completion: )]) {
515
- presentingViewController = viewController;
516
- }
517
- else {
518
- UIViewController *rootViewController = [UIViewController bnc_currentViewController ];
519
- if ([rootViewController respondsToSelector: @selector (presentViewController:animated:completion: )]) {
520
- presentingViewController = rootViewController;
521
- }
522
- }
523
-
524
- if (linkProperties.controlParams [BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT]) {
525
- @try {
526
- [shareViewController setValue: linkProperties.controlParams[BRANCH_LINK_DATA_KEY_EMAIL_SUBJECT] forKey: @" subject" ];
527
- }
528
- @catch (NSException *) {
529
- BNCLogWarning (@" Unable to setValue 'emailSubject' forKey 'subject' on UIActivityViewController." );
530
- }
531
- }
532
461
533
- if (presentingViewController) {
534
- // Required for iPad/Universal apps on iOS 8+
535
- if ([presentingViewController respondsToSelector: @selector (popoverPresentationController )]) {
536
- if ([anchorViewOrButtonItem isKindOfClass: UIBarButtonItem.class]) {
537
- UIBarButtonItem *anchor = (UIBarButtonItem*) anchorViewOrButtonItem;
538
- shareViewController.popoverPresentationController .barButtonItem = anchor;
539
- } else
540
- if ([anchorViewOrButtonItem isKindOfClass: UIView.class]) {
541
- UIView *anchor = (UIView*) anchorViewOrButtonItem;
542
- shareViewController.popoverPresentationController .sourceView = anchor;
543
- shareViewController.popoverPresentationController .sourceRect = anchor.bounds ;
544
- } else {
545
- shareViewController.popoverPresentationController .sourceView = presentingViewController.view ;
546
- shareViewController.popoverPresentationController .sourceRect = CGRectMake (0.0 , 0.0 , 40.0 , 40.0 );
547
- }
548
- }
549
- [presentingViewController presentViewController: shareViewController animated: YES completion: nil ];
550
- }
551
- else {
552
- BNCLogWarning (@" Unable to show the share sheet since no view controller is present." );
553
- }
462
+ BranchShareLink *shareLink = [[BranchShareLink alloc ] initWithUniversalObject: self linkProperties: linkProperties];
463
+ shareLink.shareText = shareText;
464
+ shareLink.completion = completion;
465
+ shareLink.completionError = completionError;
466
+ [shareLink presentActivityViewControllerFromViewController: viewController anchor: anchorViewOrButtonItem];
554
467
}
555
468
556
469
#pragma mark - Spotlight
0 commit comments