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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With