2011-06-29 28 views
6

Tôi biết làm thế nào để chia sẻ hình ảnh cô đơn:chia sẻ bội mục có sharekit trên facebook

// 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]; 

và làm thế nào để chia sẻ một liên kết cô đơn:

// 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]; 

nhưng tôi không biết làm thế nào để chia sẻ cả liên kết và hình ảnh trong cùng một thời điểm. có ai có thể giúp tôi trong việc này không?

Trả lời

2


Bạn có thể thực hiện việc này theo một trong hai cách.

1. Thông qua thuộc tính URL của SHKItem.

@property (nonatomic, retain) NSURL *URL; 

Giống như vậy:

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. Sử dụng + [itemFromDictionary:] phương pháp lớp SHKItem

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

Giống như vậy:

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]; 


... và sau đó chia sẻ mục của bạn như mong muốn. Trong trường hợp của bạn, bạn có thể hiển thị bằng cách sử dụng phương thức - [actionSheetForItem:].

+0

hi .. cũng quan tâm đến cách thêm mô tả? có nghĩa là để nói văn bản, url và hình ảnh cùng một lúc? – lakesh

+0

bất kỳ ý tưởng nào về điều đó? cần một số hướng dẫn? – lakesh

+0

@lakesh ví dụ tôi đã đưa ra hiển thị văn bản, URL và hình ảnh đang được chia sẻ trong một yêu cầu. Xem cách từ điển sử dụng 3 cặp khóa-đối tượng trong sự khởi tạo của nó. – imnk

Các vấn đề liên quan