【发布时间】:2014-04-17 08:16:38
【问题描述】:
我正在使用 FBDialogs 在 Facebook 上分享。
facebook 共享工作正常,但处理程序从未被调用(我在第一行设置了一个断点)
我的 SDK 是通过 CocoaPods 安装的
pod 'Facebook-iOS-SDK', '3.9.0'
这是代码,几乎是 facebook 开发页面上的示例。我正在使用 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;
}
【问题讨论】:
-
你检查过FaceBook会话是否打开了吗?
-
如何检查? Facebook 会话到底是什么?
标签: ios facebook sdk callback handler