我正在使用FBDialogs在Facebook上分享.
Facebook共享工作正常,但处理程序永远不会被调用(我在第一行放置断点)
我的SDK是通过CocoaPods安装的
pod 'Facebook-iOS-SDK','3.9.0'
这是代码,几乎是facebook dev页面上的示例.我正在使用ios7测试iPod.
// If the Facebook app is installed and we can present the share dialog if ([FBDialogs canPresentShareDialogWithParams:params]) { // Present the share dialog [FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call,NSDictionary *results,NSError *error) { //never gets here if(error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat: @"O comparilhando não foi bem sucedido. %@",error.description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sucesso" message:@"O compartilhando foi bem sucedido" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }}];
解:
我的老板最终弄明白了.
我在AppDelegate中错过了这个方法.没有它,Facebook无法将数据传回我的应用程序
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation { BOOL urlWasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication fallbackHandler:^(FBAppCall *call) { // incoming link processing goes here }]; return urlWasHandled; }
解决方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([[[[NSString stringWithFormat:@"%@",url] componentsSeparatedByString:@":"] objectAtIndex:0]isEqualToString:@"your FB ID"]) { return [FBSession.activeSession handleOpenURL:url]; }
可能对你有所帮助.