When I run my ios app which integrates a facebook share, the launcher screen appears and it goes back to the view controller. It does not execute the codes that displays Share Dialog
this is my code and i am not using the latest version of Facebook SDK
- (IBAction)buttonShare:(id)sender {
[self facebookPost];
}
-(void) facebookPost{
NSArray *permissions = [NSArray arrayWithObjects:@"email", @"publish_actions", @"user_friends", @"public_profile", nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if(!error) {
if(status == FBSessionStateOpen || status == FBSessionStateOpenTokenExtended) {
[FBSession setActiveSession:session];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.model.name, @"name",
self.model.categoryName, @"caption",
self.model.address, @"description",
self.model.imgURL, @"link", nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"]) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];
}
}
else{
NSLog(@"Error");
}
}];
}
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val = [kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}