我已将 FBConnect SDK 实现到我的应用程序中,并且它在模拟器上完美运行。然后,我适本地修改了应用程序的 .plist 文件,并向我的 AppDelegate 添加了当 Facebook 安装在设备上时所需的方法:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"handleOpenURL Method was called and sent the following:");
NSString *urlString = [NSString stringWithContentsOfURL:(NSURL *)url];
NSLog(@"URL String: %@", urlString);
return [[flipsideViewController facebook] handleOpenURL:url];
}
从上面的 NSLogs 以及我的应用程序在通过 Facebook 授权访问后返回前台的观察结果来看,我推断 FB 应用程序正在将控制权适本地移交给我的应用程序。不幸的是,Facebook.m 的“handleOpenURL:url”方法实际上并未按照我在 AppDelegate 中的请求被调用(即以下 NSLog 均未显示)。
- (BOOL)handleOpenURL:(NSURL *)url {
// If the URL's structure doesn't match the structure used for Facebook authorization, abort.
NSLog(@"handleOpenURL was handled by SDK. Good!");
if (![[url absoluteString] hasPrefix:[self getOwnBaseUrl]]) {
NSLog(@"handleOpenURL structure doesn't match the structure used for Facebook authorization. Aborting.");
return NO;
}
//...
结果,我的应用程序的 View Controller (我首先单击我的 facebook 按钮的地方)只是返回到屏幕,并且我放置在“fbDidLogin”方法中的代码(在我的 View Controller 中用于发布到用户的墙)永远不会像在模拟器中那样被调用。
我忽略了什么?解决此问题还需要哪些其他信息(如果有)?任何帮助将非常感激,因为我已经为此苦苦挣扎了一段时间。
重要摘要说明: 1.) 应用程序在模拟器上按需要运行。 2.) 当我从 AppDelegate 请求它时,handleOpenURL 方法没有被调用。 3.) 我没有收到任何错误/警告。 4.) 我可以在我的设备上运行 DemoApp,并且我注意到在“DemoAppAppDelegate”请求时会适本地调用 handleOpenURL 方法。
提前致谢!
最佳答案
我最终不得不将我的 facebook 对象设置为单例(存储在 appDelegate 中)。但不完全确定为什么这是必要的,因为我没有在多个 viewController 中使用 fb 对象。如果您知道为什么这是必要的,请发表评论。
请参阅以下链接了解更多信息:
handleOpenUrl and TabBar Application
关于iphone - 我的 AppDelegate 未调用 FBConnect 的 handleOpenURL 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6216825/