You can try this method to share an image with link. The image you want to share should need to be on server(i.e. you need to use link of an image )
Note:- You must have an "publish_actions" permission from facebook app
Below method is shown using the facebook sdk 4.3
In .h file
#import <FacebookSDK/FacebookSDK.h>
@property (strong, nonatomic) FBRequestConnection *requestConnection;
In .m file
-(IBAction)facebookBtn:(id)sender{
if (!FBSession.activeSession.isOpen) {
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"email", @"user_events", @"user_location", @"publish_actions"]
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", nil) message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
if (error.code!=2)
{
[alertView show];
}
}
else if (session.isOpen)
{
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
[self requestCompleted:connection forFbID:@"me" result:result error:error];
}];
// create the connection object
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request for fbid's profile
FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:@"me" result:result error:error];
[self showAlert:NSLocalizedString(@"Posted successfully", nil)];
};
// create the request object, using the fbid as the graph path
// as an alternative the request* static methods of the FBRequest class could
// be used to fetch common requests, such as /me and /me/friends
NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ" ;
// Your facebook application link
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
}];
}
else
{
FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
// create a handler block to handle the results of the request for fbid's profile
FBRequestHandler handler = ^(FBRequestConnection *connection, id result, NSError *error) {
// output the results of the request
[self requestCompleted:connection forFbID:@"me" result:result error:error];
[self showAlert:NSLocalizedString(@"Posted successfully", nil)];
};
// create the request object, using the fbid as the graph path
// as an alternative the request* static methods of the FBRequest class could
// be used to fetch common requests, such as /me and /me/friends
NSString *messageString=[NSString stringWithFormat:NSLocalizedString(@"Just parked at %@ with #ParkHero", nil),@"miami"];
NSString *imageUrl = @"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRFoE4FjiykSb-3usYJ6OuyUsa_NB0s0B13u52IKK80se0qOwPJ";
// Your facebook application link
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"https://www.facebook.com/ParkHero?fref=ts", @"link",imageUrl, @"picture",messageString,@"message",nil];
FBRequest *request=[[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/feed" parameters:params HTTPMethod:@"POST"];
[newConnection addRequest:request completionHandler:handler];
// if there's an outstanding connection, just cancel
[self.requestConnection cancel];
// keep track of our connection, and start it
self.requestConnection = newConnection;
[newConnection start];
}
}