Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)shareFeed:(FeedModel *)feedModel {
- NSString *photoURLString;
- NSString *postTitle = @"";
- NSString *fullContent = @"";
- switch (feedModel.feedType) {
- case FeedTypePostWorkout: {
- postTitle = @"Posted a workout";
- if (feedModel.postModel.photo.count > 0) {
- Photo *photo = feedModel.postModel.photo[0];
- photoURLString = photo.photoDetail.source;
- }
- fullContent = feedModel.postModel.content;
- }
- break;
- case FeedTypeOutdoorActivities: {
- postTitle = @"Posted outdoor activity";
- if (feedModel.postModel.photo.count > 0) {
- Photo *photo = feedModel.postModel.photo[0];
- photoURLString = photo.photoDetail.source;
- }
- fullContent = feedModel.postModel.content;
- }
- break;
- default:
- break;
- }
- NSMutableArray *actions = [FeedUtilities arrShareActionWithInstagram:photoURLString];
- // share here
- @weakify(self);
- @weakify(feedModel);
- [UIActionSheet showInView:self.view
- withTitle:nil
- cancelButtonTitle:@"Cancel"
- destructiveButtonTitle:nil
- otherButtonTitles:actions tapBlock:^(UIActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
- @strongify(self);
- @strongify(feedModel);
- if (buttonIndex != actions.count) {
- if ([actions[buttonIndex] isEqualToString:@"Instagram"]) {
- // Instagram
- if ([MGInstagram isAppInstalled]) {
- if (!self.instagram) {
- self.instagram = [[MGInstagram alloc] init];
- }
- [SVProgressHUD show];
- @weakify(self);
- [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:photoURLString]
- options:SDWebImageDownloaderUseNSURLCache
- progress:nil
- completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
- @strongify(self);
- [SVProgressHUD dismiss];
- if (image) {
- [self.instagram postImage:image
- withCaption:[[NSString stringWithFormat:@"%@\n%@",postTitle, fullContent] trim]
- inView:self.view delegate:self];
- } else {
- [self showWarningMessage:@"There are no images associated with this listing to share. Thank you."];
- }
- }];
- } else {
- [self showWarningMessage:@"Instagram must be installed on the device in order to post images"];
- }
- } else {
- BranchUniversalObject *branchUniversalObject = [[BranchUniversalObject alloc] initWithCanonicalIdentifier:@"petwidget/2020"];
- branchUniversalObject.title = postTitle;
- branchUniversalObject.contentDescription = fullContent;
- if (photoURLString) {
- branchUniversalObject.imageUrl = photoURLString;
- }
- [branchUniversalObject addMetadataKey:@"newsFeedId" value:feedModel.postModel.idField];
- [branchUniversalObject addMetadataKey:@"newsFeedType" value:[NSString stringWithFormat:@"%zd", feedModel.feedType]];
- BranchLinkProperties *linkProperties = [[BranchLinkProperties alloc] init];
- linkProperties.feature = @"share";
- [SVProgressHUD show];
- @weakify(self);
- [branchUniversalObject getShortUrlWithLinkProperties:linkProperties andCallback:^(NSString *url, NSError *error) {
- @strongify(self);
- [SVProgressHUD dismiss];
- if (error) {
- [self showWarningMessage:error.localizedDescription];
- } else {
- // Facebook
- if ([actions[buttonIndex] isEqualToString:@"Facebook"]) {
- FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
- if (![FBSDKAccessToken currentAccessToken]) {
- [shareDialog setMode:FBSDKShareDialogModeAutomatic];
- }
- FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
- content.contentURL = [NSURL URLWithString:url];
- shareDialog.fromViewController = self;
- shareDialog.shareContent = content;
- shareDialog.delegate = self;
- [shareDialog show];
- } else {
- // More
- UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL URLWithString:url]] applicationActivities:nil];
- activityViewController.excludedActivityTypes = @[UIActivityTypeAirDrop, UIActivityTypePostToFacebook];
- @weakify(self);
- [activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
- @strongify(self);
- if (completed) {
- [self sharer:nil didCompleteWithResults:nil];
- }
- }];
- [self presentViewController:activityViewController animated:YES completion:nil];
- }
- }
- }];
- }
- }
- }];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement