I'm trying to integrate an iOS application with Facebook. Login and most of the features work well but I am experiencing a little-big problem when I try to get FBWebDialogs to share something that user has posted. It works well if it is called directly just after posting (calling the function) but crashes when I try to do the same from an alert view, it just starts to appear and suddenly disappears before loading completely without breaking the app and no error is thrown. It works using new Facebook features in iOS 6 that has native view instead FBWebDialogs when user has logged within iPhone's settings. I'm using a third party library in order to customize alert view but it does the same with standard alert view.
I think it is something to be with dismissing view but not enough knowledge about iOS to know for sure. Any idea?. Thank you.
That's the code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex)
{
case 1:
{
[self sharePostOnFacebook];
break;
}
default:
break;
}
}
The next method is called but modal view never comes to appear completely. It just flashes and disappears
-(void) sharePostOnFacebook
{
if (shareData !=nil && [[shareData objectForKey:@"success"] boolValue])
{
NSString *caption = [shareData objectForKey:@"caption"];
. ..........
BOOL displayedNativeDialog =
[FBNativeDialogs
presentShareDialogModallyFrom:self
initialText:description
image:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:picture]]]
url:[NSURL URLWithString:link]
handler:^(FBNativeDialogResult result, NSError *error) {
.........
}];
// Fallback, show the view controller that will post using me/feed
if (!displayedNativeDialog)
{
[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
// Put together the dialog parameters
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
.............
nil];
FBSession *activeSession = [FBSession activeSession];
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:activeSession
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
........
}];
}
}
}