Social action sheet (like on iOS 6)

20,681

Solution 1

    NSString *textToShare = @"your text";
    UIImage *imageToShare = [UIImage imageNamed:@"yourImage.png"];
    NSArray *itemsToShare = @[textToShare, imageToShare];
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll]; //or whichever you don't need
    [self presentViewController:activityVC animated:YES completion:nil];

See UIActivityViewController documentation: https://developer.apple.com/documentation/uikit/uiactivityviewcontroller

Solution 2

It is actually a custom action sheet that you can easily create as well. In addition to this, you might want to look at this share kit framework.

https://github.com/ShareKit/ShareKit

Share:
20,681
MCKapur
Author by

MCKapur

Updated on July 26, 2022

Comments

  • MCKapur
    MCKapur almost 2 years

    on iOS 6 a change was that when you want to share something it brings up an action sheet similar to this:

    I have seen a few other apps that use this, is there a native way to do this without making a custom action sheet?

    Thanks!

  • j9suvak
    j9suvak over 11 years
    Pretty much as is, into whatever method is pertinent to you (i.e. button action, table row selected.) Just substitute 'your text', 'yourImage.png' and whichever activity types you don't want into the excludedActivityTypes line (see documentation link above for full list.) If the user's device isn't able to use a certain activity, it will show or not accordingly. For example, Weibo doesn't show on my device in the U.S. or the Middle East; Twitter won't show if they don't use Twitter on their device, etc.