Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.66 KB | None | 0 0
  1. - (void)shareFeed:(FeedModel *)feedModel {
  2. NSString *photoURLString;
  3. NSString *postTitle = @"";
  4. NSString *fullContent = @"";
  5.  
  6. switch (feedModel.feedType) {
  7. case FeedTypePostWorkout: {
  8.  
  9. postTitle = @"Posted a workout";
  10. if (feedModel.postModel.photo.count > 0) {
  11. Photo *photo = feedModel.postModel.photo[0];
  12. photoURLString = photo.photoDetail.source;
  13. }
  14. fullContent = feedModel.postModel.content;
  15. }
  16. break;
  17.  
  18. case FeedTypeOutdoorActivities: {
  19.  
  20. postTitle = @"Posted outdoor activity";
  21. if (feedModel.postModel.photo.count > 0) {
  22. Photo *photo = feedModel.postModel.photo[0];
  23. photoURLString = photo.photoDetail.source;
  24. }
  25. fullContent = feedModel.postModel.content;
  26. }
  27. break;
  28.  
  29. default:
  30. break;
  31. }
  32.  
  33.  
  34. NSMutableArray *actions = [FeedUtilities arrShareActionWithInstagram:photoURLString];
  35. // share here
  36. @weakify(self);
  37. @weakify(feedModel);
  38.  
  39. [UIActionSheet showInView:self.view
  40. withTitle:nil
  41. cancelButtonTitle:@"Cancel"
  42. destructiveButtonTitle:nil
  43. otherButtonTitles:actions tapBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
  44. @strongify(self);
  45. @strongify(feedModel);
  46. if (buttonIndex != actions.count) {
  47. if ([actions[buttonIndex] isEqualToString:@"Instagram"]) {
  48. // Instagram
  49. if ([MGInstagram isAppInstalled]) {
  50. if (!self.instagram) {
  51. self.instagram = [[MGInstagram alloc] init];
  52. }
  53. [SVProgressHUD show];
  54. @weakify(self);
  55. [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:photoURLString]
  56. options:SDWebImageDownloaderUseNSURLCache
  57. progress:nil
  58. completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
  59. @strongify(self);
  60. [SVProgressHUD dismiss];
  61. if (image) {
  62. [self.instagram postImage:image
  63. withCaption:[[NSString stringWithFormat:@"%@\n%@",postTitle, fullContent] trim]
  64. inView:self.view delegate:self];
  65.  
  66. } else {
  67. [self showWarningMessage:@"There are no images associated with this listing to share. Thank you."];
  68. }
  69. }];
  70. } else {
  71. [self showWarningMessage:@"Instagram must be installed on the device in order to post images"];
  72. }
  73.  
  74. } else {
  75.  
  76. BranchUniversalObject *branchUniversalObject = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"petwidget/2020"];
  77. branchUniversalObject.title = postTitle;
  78. branchUniversalObject.contentDescription = fullContent;
  79. if (photoURLString) {
  80. branchUniversalObject.imageUrl = photoURLString;
  81. }
  82. [branchUniversalObject addMetadataKey:@"newsFeedId" value:feedModel.postModel.idField];
  83. [branchUniversalObject addMetadataKey:@"newsFeedType" value:[NSString stringWithFormat:@"%zd", feedModel.feedType]];
  84.  
  85. BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
  86. linkProperties.feature = @"share";
  87.  
  88. [SVProgressHUD show];
  89. @weakify(self);
  90. [branchUniversalObject getShortUrlWithLinkProperties:linkProperties andCallback:^(NSString *url, NSError *error) {
  91. @strongify(self);
  92. [SVProgressHUD dismiss];
  93. if (error) {
  94. [self showWarningMessage:error.localizedDescription];
  95. } else {
  96. // Facebook
  97. if ([actions[buttonIndex] isEqualToString:@"Facebook"]) {
  98.  
  99. FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
  100.  
  101. if (![FBSDKAccessToken currentAccessToken]) {
  102. [shareDialog setMode:FBSDKShareDialogModeAutomatic];
  103. }
  104.  
  105. FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
  106. content.contentURL = [NSURL URLWithString:url];
  107. shareDialog.fromViewController = self;
  108. shareDialog.shareContent = content;
  109. shareDialog.delegate = self;
  110. [shareDialog show];
  111.  
  112. } else {
  113. // More
  114. UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:url]] applicationActivities:nil];
  115.  
  116. activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop, UIActivityTypePostToFacebook];
  117. @weakify(self);
  118. [activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
  119. @strongify(self);
  120. if (completed) {
  121. [self sharer:nil didCompleteWithResults:nil];
  122. }
  123. }];
  124. [self presentViewController:activityViewController animated:YES completion:nil];
  125. }
  126. }
  127. }];
  128. }
  129. }
  130. }];
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement