sharing multiples items with sharekit on facebook
Asked Answered
D

1

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?

Damar answered 29/6, 2011 at 15:56 Comment(0)
A
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.

Afghanistan answered 16/4, 2012 at 13:34 Comment(6)
hi.. interested how to add description as well? meaning to say text, url and image at the same time?Christianism
any idea on that? need some guidance?Christianism
@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.Afghanistan
when i use your second method, I get this error: -[NSURL length]: unrecognized selector sent to instance 0xadb73c0 ? Not sure how to solve this...Christianism
@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.Lemuellemuela
Has this functionality been removed form share kit?Imes

© 2022 - 2024 — McMap. All rights reserved.