I am trying to implement the native Share dialog from Facebook in a sample application.
Seem to have some problem in doing so.
Things I have done so far:
- (IBAction)shareButtonClicked:(id)sender
{
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
NSString *str_img = [NSString stringWithFormat:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
NSDictionary *params = @{
@"name" :[NSString stringWithFormat:@"Facebook SDK for iOS"],
@"caption" : @"Build great Apps",
@"description" :@"Welcome to iOS world",
@"picture" : str_img,
@"link" : @"",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
//NSLog(@"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
//NSLog(@"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
//NSLog(@"Story published.");
[self.indicator stopAnimating];
}
}}];
}
}];
return;
}