如果安装了Facebook应用程序,则PFFacebookUtils登录方法不起作用 [英] PFFacebookUtils login methods do nothing if Facebook app is installed

查看:61
本文介绍了如果安装了Facebook应用程序,则PFFacebookUtils登录方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪.我正在尝试登录Facebook,如果设备上未安装Facebook应用程序,则一切运行正常.但是,如果有这个应用程序,那么什么也不会发生.根本不值一提.永远不会调用完成块,并且不会显示任何登录对话框.这是我非常简单的代码:

This is very weird. I'm trying to login to Facebook and everything is working fine if there's no Facebook app is installed on the device. But if there's this app then nothing happens. Just nothing. Completion block is never called and no login dialog appears. This is my very simple code:

[PFFacebookUtils logInInBackgroundWithReadPermissions:@[@"public_profile"] block:^(PFUser *user, NSError *error)
 {
     NSLog(@"Completion");

 }];

我在 applicationDidFinishLauncing 中也有以下代码:

[Parse setApplicationId:kPAParseApplicationId clientKey:kPAParseClientKey];    
[PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];

并且我实现了以下方法:

and I have the following method implemented:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                   openURL:url
                                         sourceApplication:sourceApplication
                                                annotation:annotation];

}

我还需要注意以下几点:有时,即使安装了该应用程序,它也很少起作用.工作,然后再次停止工作而没有任何原因.有人遇到过这样的问题吗?谢谢!

I also need to note the following: sometimes, very rarely, it works even with the app installed. Works and then again stops working without any reason. Did anyone encounter such a problem? Thanks!

推荐答案

我知道了.问题出在Facebook SDK本身,我已经设法解决了.它与是否安装 Facebook 应用无关.

I've figured it out. The problem was in the Facebook SDK itself and I've managed to fix it. It has nothing to do with Facebook app being installed or not.

幸运的是, FBSDKLoginKit FBSDKCoreKit 是开源的,因此我能够找到问题所在.因此,仅当 FBSDKLoginManager 具有从 Facebook 服务器加载的有效SDK配置时,才允许登录.如果不这样做,那么它甚至什么也不做,甚至不会记录一些错误消息来帮助开发人员.那么,有时它没有活动配置的原因是什么.原因是 FBSDKURLConnection 不在主运行循环上安排其 NSURLConnection .因此,如果在后台线程上调用其 start 方法,则可以调用 NSURLConnection 委托方法,也可以不调用它们.如果没有,则不会加载新配置,您将无法登录.所以我要做的就是像这样修改 FBSDKURLConnection start 方法:

Luckily, FBSDKLoginKit and FBSDKCoreKit are open source so I was able to track down the problem. So, FBSDKLoginManager allows login only if it has an active SDK configuration loaded from Facebook server. If it doesn't then it simply do nothing without even logging some error message to help the developer. So what is the reason it doesn't have active configuration sometimes. The reason is that FBSDKURLConnection doesn't schedule its NSURLConnection on the main run loop. So if its start method is called on background thread then NSURLConnection delegate methods may be called or they may be not called. And if they are not then there's no new configuration loaded and you are unable to login. So what I did was simply modify FBSDKURLConnection's start method like this:

- (void)start
{
    [_connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
                      forMode:NSDefaultRunLoopMode];
    [_connection start];
}

现在可以正常工作

这篇关于如果安装了Facebook应用程序,则PFFacebookUtils登录方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆