Skip to content

Instantly share code, notes, and snippets.

@alex-cellcity
Created September 2, 2011 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-cellcity/1188061 to your computer and use it in GitHub Desktop.
Save alex-cellcity/1188061 to your computer and use it in GitHub Desktop.
ShareKit share facebook stream with image (Stream Attachments)
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];
#define FBImageURL @"FBImageURL"
- (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