31

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!

MCKapur
  • 9,127
  • 9
  • 58
  • 101

2 Answers2

79
    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

Cœur
  • 37,241
  • 25
  • 195
  • 267
j9suvak
  • 1,120
  • 2
  • 9
  • 14
  • 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. – j9suvak Nov 26 '12 at 19:41
4

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

kkocabiyik
  • 4,246
  • 7
  • 30
  • 40