You need to add Social.framework in your project.
Add to your file following #import "Social/Social.h"
You can create 3 type of service:
I have created service of Facebook.
I have added image which will be posted with the message and URL on the Facebook page. Here is what the message looks like on FB.
Following are some screenshots of the app running.
Link to download the sample code.
Add to your file following #import "Social/Social.h"
You can create 3 type of service:
SLServiceTypeTwitter;
SLServiceTypeFacebook;
SLServiceTypeSinaWeibo;
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(@"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(@"Posted....");
}
break;
}};
[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
[fbController setInitialText:@"Check out this article."];
[fbController addURL:[NSURL URLWithString:@"http://soulwithmobiletechnology.blogspot.com/"]];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
I have added image which will be posted with the message and URL on the Facebook page. Here is what the message looks like on FB.
Following are some screenshots of the app running.
If the Facebook account is not set up on device, it gives you this pop up. |
SLComposeViewController with added URL and Image. |
SLComposeViewController with added text,URL and image, Also location has been set on the post just like we can do on our Facebook page. |
You can change the album in which you want to post this image. |
You can choose which group you want to display this post to. |
Link to download the sample code.
No need to use __block there
ReplyDeleteIS there any way to post the photo in a nwe album, which name is given by the app?
ReplyDeleteYou shouldn't use :
ReplyDeleteif([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
because on device (not simulator) it won't prompt for user to configure facebook if no account were set up.
This comment has been removed by the author.
ReplyDeletewhen i come to 1st snapshot (in above screen shots) by clicking share it , after clicking setting button or cancel button which are in first snapshot. it is simply dismissed and facebook section is also dismissed when i click any button and remains on same page.
ReplyDeletecan anyone please tell me why it is happening ??
Thank you
Good example thank u so much!. How to post video file to Facebook
ReplyDeleteany chance you make a similar tutorial to receive a certain facebook/twitter account live feed? would appreciate
ReplyDeletethanks
is there any way to post something without the pop-up compose view if you have a variable with a preloaded message?
ReplyDeletePerhaps just have a button that posts to the respective FB account and only have a alert box that saids your message has been posted.
is there any way to post something without the pop-up compose view if you have a variable with a preloaded message?
ReplyDeletePerhaps just have a button that posts to the respective FB account and only have a alert box that saids your message has been posted.
not working
ReplyDeleteimage is not getting upload for me ,but all other url and all getting shared
ReplyDeletein your samplecode also image is not getting upload
ReplyDeleteHas anyone been able to allow posting image to a Group Album? Albums show up when 'my page' is selected, but if Friends or Groups are selected then have no option to select an album.
ReplyDelete