Add the below code to share text on facebook using Facebook SDK 4.x
FBSDKGraphRequestConnection *connection =[[FBSDKGraphRequestConnection alloc]init]; NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Your_message_here_to_share_FB", @"message", nil]; FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST"]; [connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if(error){ NSLog(@"Failed to share"); } else{ NSLog(@"Updated successfully"); } }];
* Add code to share photos below.
FBSDKGraphRequestConnection *connection =[[FBSDKGraphRequestConnection alloc]init]; NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: image, @"picture", @"Your_text_here",@"message", nil]; FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"]; [connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if(result) { NSLog(@"Posting the image is success, the result is%@",result); } else if(error) { NSLog(@"Error occured while posting image %@",error); } }]; [connection start];
source share