Search code examples
iosfacebookcocoa-touchfacebook-ios-sdkparse-platform

Parse Facebook Dialog Delegate methods not being called


I'm using the Parse SDK to implement a Facebook apprequests dialog in my app. For all intents and purposes it just wraps the Facebook SDK, prefixing Facebook methods with PF_.

I use this code to prepare and raise the dialog:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat:@"I just challenged you to a game!"], @"message",
 [friendIds componentsJoinedByString:@"," ], @"to",
 nil];

PF_FBSession *session = [PFFacebookUtils session];
PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:nil];

facebook.accessToken = session.accessToken;
facebook.expirationDate = session.expirationDate;

[facebook dialog:@"apprequests" andParams:params andDelegate:self];

This works well, I'm getting the dialog, I'm able to invite friends to play with the app.

The problem is that the delegate methods are not being called, even though I've set the view controller as a PF_FBDialogDelegate:

@interface ChallengeFriendsViewController : UIViewController <UITableViewDelegate, PF_FBDialogDelegate> {
    NSArray *facebookFriends;
    NSMutableArray *selectedFriends;
}

These are some of the delegate methods I'm talking about:

- (void)dialog:(PF_FBDialog *)dialog didFailWithError:(NSError *)error {
    NSLog(@"Error in Dialog: %@", error);
}

- (void)dialogDidNotCompleteWithUrl:(NSURL *)url {
    NSLog(@"Failure on Facebook server side");
}

- (void)dialogCompleteWithUrl:(NSURL *)url {
    NSLog(@"Did complete with URL");
    [self.navigationController popViewControllerAnimated:YES];
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

- (void)dialogDidNotComplete:(PF_FBDialog *)dialog {
    NSLog(@"Cancelled");
    [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
}

Without these methods being called I'm really not able to handle the sharing in an intuitive way. I'm stumped as to why they wouldn't be called and feel I've tried everything. Any pointers to where I'm going wrong?


Solution

  • I finally got around the problem by using the facebook instance provided by PFFacebookUtils. This is deprecated but appears to be the only way to make it call the correct delegate methods at the moment.

    Replaced:

    PF_Facebook *facebook = [[PF_Facebook alloc] initWithAppId:session.appID andDelegate:nil];
    

    With:

    PF_Facebook *facebook = [PFFacebookUtils facebook];
    

    Thanks to JP and Aromal for your input.