Created
September 2, 2011 06:50
-
-
Save alex-cellcity/1188061 to your computer and use it in GitHub Desktop.
ShareKit share facebook stream with image (Stream Attachments)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *title = @"Sed adipiscing ornare risus. Morbi est est, blandit sit amet, sagittis vel, euismod vel, velit. Pellentesque egestas sem. Suspendisse commodo ullamcorper magna."; | |
NSString *imageURL = @"http://img.chinaluxus.com/pic/spts/2011/05/19/20110519080415136.jpg"; | |
NSURL *url = [NSURL URLWithString:@"http://example.com"]; | |
SHKItem *item = [SHKItem URL:url title:title]; | |
[item setCustomValue:imageURL forKey:FBImageURL]; | |
[SHKFacebook shareItem:item]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define FBImageURL @"FBImageURL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)send | |
{ | |
if (item.shareType == SHKShareTypeURL) | |
{ | |
self.pendingFacebookAction = SHKFacebookPendingStatus; | |
SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease]; | |
dialog.delegate = self; | |
dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:"); | |
// hack for facebook steam with image | |
if ([item customValueForKey:FBImageURL]!=nil) { | |
NSURL *imageURL = [NSURL URLWithString:[item customValueForKey:FBImageURL]]; | |
dialog.attachment = [NSString stringWithFormat: | |
@"{\ | |
\"name\":\"%@\",\ | |
\"href\":\"%@\",\ | |
\"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]\ | |
}", | |
item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title), | |
SHKEncodeURL(item.URL), | |
SHKEncodeURL(imageURL), | |
SHKEncodeURL(item.URL) | |
]; | |
} else { | |
dialog.attachment = [NSString stringWithFormat: | |
@"{\ | |
\"name\":\"%@\",\ | |
\"href\":\"%@\"\ | |
}", | |
item.title == nil ? SHKEncodeURL(item.URL) : SHKEncode(item.title), | |
SHKEncodeURL(item.URL) | |
]; | |
} | |
dialog.defaultStatus = item.text; | |
dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]", | |
SHKEncode(SHKMyAppName), | |
SHKEncode(SHKMyAppURL)]; | |
[dialog show]; | |
} | |
else if (item.shareType == SHKShareTypeText) | |
{ | |
self.pendingFacebookAction = SHKFacebookPendingStatus; | |
SHKFBStreamDialog* dialog = [[[SHKFBStreamDialog alloc] init] autorelease]; | |
dialog.delegate = self; | |
dialog.userMessagePrompt = SHKLocalizedString(@"Enter your message:"); | |
dialog.defaultStatus = item.text; | |
dialog.actionLinks = [NSString stringWithFormat:@"[{\"text\":\"Get %@\",\"href\":\"%@\"}]", | |
SHKEncode(SHKMyAppName), | |
SHKEncode(SHKMyAppURL)]; | |
[dialog show]; | |
} | |
else if (item.shareType == SHKShareTypeImage) | |
{ | |
self.pendingFacebookAction = SHKFacebookPendingImage; | |
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease]; | |
dialog.delegate = self; | |
dialog.permission = @"photo_upload"; | |
[dialog show]; | |
} | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment