iosobjective-cuiwebviewrssios-sharesheet

Getting the native "share sheet" to pull up when item button is pressed


I am working on finishing an rss reader app for my internship and the last thing I need to implement is a "Share" button on the top right corner of the uiwebview that displays the mobile site link for the article.

Here is a screenshot of the web view navigation controller:

enter image description here

I used a free open source code project to get this done since I don't have much experience in xcode and I had to get it done in a short amount of time. As you can see from the screenshot, the uiwebview covers the whole controller and I couldnt find anyway to simply put a button on the uinaviagtionbar since it's not there. When I placed an "Item" under the "Navigation Item" into the detail scene in the left panel and ran the project, it does show up in the web view's navigation bar. It just says "Item" and when clicked does nothing obviously:

enter image description here

So my question is, how do I programmatically, or any other way, set it so that when clicked this share sheet will show up:

enter image description here

I have been on this all week trying various different ways from other answers and the minimal amount of info from the web. Nothing seems to be working for me and there isn't any clear tutorials on this. I only have two days left to complete this app and this is the last thing I need to it do for it to be ready. If anyone would be kind enough to take the time and possibly provide some sort of step-by-step so that I may also learn (and have this answer to view for future endeavors) I would be extremely appreciative.

Thanks


Solution

  • Put this code inside your button action

    -(void) showSharingActivity {
        NSString *string = @"string to share";
        NSURL *URL = [NSUrl urlWithString:@"https://www.google.co.in"];
    
        UIActivityViewController *activityViewController =
          [[UIActivityViewController alloc] initWithActivityItems:@[string, URL]
                                            applicationActivities:nil];
        [navigationController presentViewController:activityViewController
                                              animated:YES
                                            completion:^{
          // ...
        }];
    }
    

    And add a button to your navigation bar like this

    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Show" style:UIBarButtonItemStylePlain target:self action:@selector(showSharingActivity)];          
    self.navigationItem.rightBarButtonItem = anotherButton;