IOS登录PFLoginViewController didLoginUser通过Facebook登录时不会调用代理,为什么? [英] IOS Parses PFLoginViewController didLoginUser Delegate is not being called when logging in via Facebook, why?

查看:301
本文介绍了IOS登录PFLoginViewController didLoginUser通过Facebook登录时不会调用代理,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常奇怪的问题,因为我的Facebook登录在我更新到Xcode 6和iOS 8之前正在工作。为了使这个更奇怪的Twitter工作得很好,但是Facebook没有调用didLogin回调。



这是我在AppDelegate中所做的:

  @interface AppDelegate:UIResponder< ; UIApplicationDelegate,NSURLConnectionDataDelegate,UITabBarControllerDelegate,PFLogInViewControllerDelegate,PFSignUpViewControllerDelegate> 

然后我设置Facebook& Twitter在应用程序:didFinishLaunchingWithOptions:

  [解析setApplicationId:PARSE_APPLICATION_ID 
clientKey:PARSE_CLIENT_KEY];

[PFFacebookUtils initializeFacebook];
[PFTwitterUtils initializeWithConsumerKey:TWITTER_CONSUMER_KEY
consumerSecret:TWITTER_CONSUMER_SECRET];

设置完成后,我设置了rootViewController,如下所示:

  self.welcomeViewController = [[ConfigViewController alloc] init]; 

self.navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
[self.navController setNavigationBarHidden:NO];

self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];

$ c> ConfigViewController 我做了以下检查:

  //强制退出测试
// [(AppDelegate *)[[UIApplication sharedApplication] delegate] logOut];

//如果没有登录,现在登录视图控制器
if(![PFUser currentUser]){
[(AppDelegate *)[[UIApplication sharedApplication] delegate] presentLoginViewControllerAnimated:没有];
返回;
}

//现在UI
[(AppDelegate *)[[UIApplication sharedApplication] delegate] presentTabBarController];

此时如果用户未登录,则在 presentLoginViewControllerAnimated

  //自定义登录视图控制器
loginViewController = [[LoginViewController alloc ] 在里面];
loginViewController.delegate = self;
loginViewController.facebookPermissions = @ [@email,@public_profile,@user_friends];
loginViewController.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten | PFLogInFieldsLogInButton;

//自定义注册视图控制器
signUpViewController = [[SignupViewController alloc] init];
signUpViewController.delegate = self;
signUpViewController.fields = PFSignUpFieldsDefault;
loginViewController.signUpController = signUpViewController;

[self.welcomeViewController presentViewController:loginViewController animated:NO completion:nil];

这里提供了loginViewController。如果用户点击twitter按钮,他将无需登录。如果Facebook按钮被点击,Facebook确认屏幕显示,我点击OK,然后返回到我的loginViewController。我需要调用它:

   - (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)用户

所以我可以关闭loginViewController,并执行任何其他操作。任何想法为什么会发生这种情况?



再次,为什么loginViewController:didLogInUser:委托不被调用Facebook?



任何帮助都是非常感激的!





经过多次测试,很多头痛都是最新的。

如果我拧紧了我的Info.plist中的 URL方案它可以工作。我将名称从 URL方案更改为 URL Scheme ,我收到以下错误:

  FBSDKLog:无法使用Facebook应用程序或Safari进行授权,fb6 **************未注册为URL方案

即使我收到这个错误,我得到一个屏幕弹出窗口登录到FaceBook。我填写,我在,它的工作,我可以用Facebook登录。这似乎不方便,但它正在工作。



其他测试/我试过的东西是下载Facebook应用程序,尝试登录,登录没有Facebook应用程序(通过safari ),在我的welcomeViewController中代替AppDelegate实现代理,并更新Parse / Facebook SDK。



我认为这个问题可能与打开其他应用程序(如Facebook或Safari)有关。我倾向于这一点的原因是因为twitter屏幕是一个模态弹出的视图,它的工作没有问题。当Facebook给我这个错误,它不会切换到safari或Facebook应用程序,而是显示一个模态弹出的登录,它的工作正常。这使我相信该问题与切换应用程序有关,并且没有正确接收回调。



我也有第三个登录选项,我忽略了提及。这个第三个选项只是通过在没有社交媒体帐户的情况下注册而工作,这也是正常的。



由于 Matt Tang

解决方案

事实证明,我意外删除/评论了这3个回调的部分,这是来源的问题。最后,我的解决方案是实现应用程序:handleOpenURL:应用程序:openURL:sourceApplication:annotation:

  // Facebook oauth回调
- (BOOL)应用程序:(UIApplication *)应用程序handleOpenURL:(NSURL *) url {
return [FBSession.activeSession handleOpenURL:url];


- (BOOL)应用程序:(UIApplication *)应用程序openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication注释:(id)注释{
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}

并取消注释此行:

  [FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]]; 

我在这个电话里面回来了:



- (void)applicationDidBecomeActive :( UIApplication *)应用程序;


This is a very strange problem because my Facebook login was working before I updated to Xcode 6 and iOS 8. To make this even more strange Twitter is working excellent but Facebook isn't calling the didLogin callback.

Here is what I am doing in my AppDelegate:

@interface AppDelegate : UIResponder <UIApplicationDelegate, NSURLConnectionDataDelegate, UITabBarControllerDelegate, PFLogInViewControllerDelegate, PFSignUpViewControllerDelegate>

Then I setup Facebook & Twitter in application:didFinishLaunchingWithOptions:

[Parse setApplicationId:PARSE_APPLICATION_ID
              clientKey:PARSE_CLIENT_KEY];

[PFFacebookUtils initializeFacebook];
[PFTwitterUtils initializeWithConsumerKey:TWITTER_CONSUMER_KEY
                           consumerSecret:TWITTER_CONSUMER_SECRET];

After setting these up I setup my rootViewController like so:

self.welcomeViewController = [[ConfigViewController alloc] init];

self.navController = [[UINavigationController alloc] initWithRootViewController:self.welcomeViewController];
[self.navController setNavigationBarHidden: NO];

self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];

In the viewDidAppear of my ConfigViewController I do the following check:

// Force logout for testing
//[(AppDelegate *)[[UIApplication sharedApplication] delegate] logOut];

// If not logged in, present login view controller
if (![PFUser currentUser]) {
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] presentLoginViewControllerAnimated:NO];
    return;
}

// Present UI
[(AppDelegate *)[[UIApplication sharedApplication] delegate] presentTabBarController];

At this point if the user is not logged in the following happens in presentLoginViewControllerAnimated:

// Customize the Log In View Controller
loginViewController = [[LoginViewController alloc] init];
loginViewController.delegate = self;
loginViewController.facebookPermissions = @[@"email",@"public_profile",@"user_friends"];
loginViewController.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsTwitter | PFLogInFieldsFacebook | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten | PFLogInFieldsLogInButton;

// Customize the Sign Up View Controller
signUpViewController = [[SignupViewController alloc] init];
signUpViewController.delegate = self;
signUpViewController.fields = PFSignUpFieldsDefault;
loginViewController.signUpController = signUpViewController;

[self.welcomeViewController presentViewController:loginViewController animated:NO completion:nil];

Here the loginViewController is presented. If the user taps on the twitter button he will login without any trouble. If the Facebook button is tapped however, the Facebook confirm screen shows up, I hit ok, then it returns to my loginViewController. I need for this to be called:

- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user

So that I can dismiss the loginViewController and also perform any additional actions. Any idea as to why this could be happening?

Again, Why loginViewController:didLogInUser: delegate not being called for Facebook?

Any help is GREATLY appreciated!

[EDIT]

After much testing and many headaches here is the latest on this.

If I screw up the URL Schemes in my Info.plist it works. I changed the name from URL Schemes to URL Scheme and I get the following error:

FBSDKLog: Cannot use the Facebook app or Safari to authorize, fb6************** is not registered as a URL Scheme

Even though I get this error, I am getting a screen popup to log into FaceBook. I fill it out and I am in, it works, I can login with Facebook. This doesn't seem convenient but it is working.

Other tests/things I tried were downloading the Facebook app and trying to login, login without the Facebook app (through safari), implementing the delegates in my welcomeViewController instead of my AppDelegate, and updating Parse/Facebook SDKs.

I think the problem might have something to do with opening up another app such as Facebook or safari. The reason I am leaning towards this is because the twitter screen is a modally popped up view and it works without an issue. When Facebook gives me this error, it doesn't switch to safari or the Facebook app, instead it shows a modally popped up login and it works fine. This leads me to believe that the problem is related to switching apps and not receiving the callback properly.

I also have a third login option which I neglected to mention. This third option works just by signing up without a social media account, and this is also working.

HUGE thanks to Matt Tang for pointing me in the right direction.

解决方案

It turns out that I had accidentally deleted/commented out portions of these 3 callbacks, this was the source of the problem. In the end, the solution for me was to implement application:handleOpenURL: and application:openURL:sourceApplication:annotation:

// Facebook oauth callback
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [FBSession.activeSession handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}

and to uncomment this line:

[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];

Which I had inside of this call back:

- (void)applicationDidBecomeActive:(UIApplication *)application;

这篇关于IOS登录PFLoginViewController didLoginUser通过Facebook登录时不会调用代理,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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