Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios8 - how to show the default share sheet

Tags:

ios

I want to present and use the default "share to other service" sheet in order to allow sharing to twitter, facebook, email, etc.

I can't figure out how to show this view from my app - how can i do that?

like image 389
Erik Sapir Avatar asked Nov 17 '14 23:11

Erik Sapir


People also ask

How do I customize my iPhone Share menu?

Control-click on any file in the Finder, select Share, and click More. You'll see a list of items that you can add and remove from the Share menu. Tick the items that you want to keep in the menu; untick the items you want to remove. Your changes will save automatically.

What does show in share sheet mean on iPhone?

The Share Sheet is the collection of actions that become available when you tap the Share icon available in most of the common app. For example, if you wanted to send someone a photo from the Photo Library, you would display the photo in the Photos app and tap Share in order to see the send options.

Where is iOS share sheet?

The Share button is easy enough to recognize; it looks like a box with an arrow coming out of it. This button often shows up in the toolbar for apps like Photos and Safari. Tapping the button will grab the photo, video, or web page you're currently viewing and open the Share Sheet for you.


2 Answers

You can use the simple activity controller to show default sharing apps using:

 NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
 UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
 activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

 [self presentViewController:activityViewController animated:YES completion:nil];

And you can use its completion handler too:

[activityViewController setCompletionHandler:^(NSString *act, BOOL done)
     {
               //Code here when the action performed.

     }];

This will show all default sharing apps.

like image 83
Esha Avatar answered Sep 30 '22 15:09

Esha


Here is a solution for a "share" popup triggered from a UIBarButtonItem, that works on both iPhone and iPad:

// "Share" action
- (IBAction)share:(UIBarButtonItem *)sender {
    NSString* title = "Content Title";
    NSString* link = "http://example.com/content.url";
    NSArray* dataToShare = @[title, link];

    UIActivityViewController* activityViewController =
    [[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                      applicationActivities:nil];


    // This is key for iOS 8+
    activityViewController.popoverPresentationController.barButtonItem = sender; 

    [self presentViewController:activityViewController
                       animated:YES
                     completion:^{}];
}
like image 22
eduludi Avatar answered Sep 30 '22 15:09

eduludi