6

I know how to share an image lonely:

// Create a UIImage.
UIImage *image = [UIImage imageNamed:@"ShareKit.jpg"];

// Wrap the UIImage within the SHKItem class
SHKItem *item = [SHKItem image:image title:@"This image was sent with ShareKit!"];

// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];

and how to share a link lonely:

// Create an NSURL. This could come from anywhere in your app.
NSURL *url = [NSURL URLWithString:@"http://mobile.tutsplus.com"];

// Wrap the URL within the SHKItem Class
SHKItem *item = [SHKItem URL:url title:@"Mobiletuts!"];

// Create a ShareKit ActionSheet and Assign the Sheet an SHKItem
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];

// Display the ActionSheet in the current UIView
[actionSheet showInView:self.view];

but I don't know how to share both link and image in the same time. Can anyone help me on this?

user821470
  • 61
  • 3

1 Answers1

2


You can do this one of two ways.

1. Through the URL property of SHKItem.

@property (nonatomic, retain)   NSURL *URL;

Like so:

NSURL *url = [NSURL URLWithString:@"http://mobile.tutsplus.com"];
UIImage *image = [UIImage imageNamed:@"ShareKit.jpg"];
SHKItem *item = [SHKItem image:image title:@"This image was sent with ShareKit!"];
[item setURL:url];


2. Using the +[itemFromDictionary:] class method of SHKItem

+ (SHKItem *)itemFromDictionary:(NSDictionary *)dictionary;

Like so:

NSString *urlString = @"http://mobile.tutsplus.com";
UIImage *image = [UIImage imageNamed:@"ShareKit.jpg"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:urlString, @"URL", image, @"image", @"This image was sent with ShareKit!", @"title", nil];
SHKItem *item = [SHKItem itemFromDictionary:dictionary];


... and then sharing your item as desired. In your case, you can display using the -[actionSheetForItem:] method.

imnk
  • 4,342
  • 3
  • 29
  • 31
  • hi.. interested how to add description as well? meaning to say text, url and image at the same time? – lakshmen Jan 21 '13 at 09:43
  • any idea on that? need some guidance? – lakshmen Jan 21 '13 at 09:54
  • @lakesh the example I've given shows text, URL and image being shared in one request. See how the dictionary uses 3 key-object pairs in it's instantiation. – imnk Jan 21 '13 at 17:20
  • when i use your second method, I get this error: -[NSURL length]: unrecognized selector sent to instance 0xadb73c0 ? Not sure how to solve this... – lakshmen Jan 22 '13 at 02:19
  • @lakesh change the url to an NSString and it will work. The initialization from the SHKItem assumes you entered an NSString and not an NSURL. – Myth1c Feb 17 '13 at 11:48
  • Has this functionality been removed form share kit? – David Nelson May 02 '14 at 12:38