IOS Parses PFLoginViewController didLoginUser Delegate 在通过 Facebook 登录时没有被调用,为什么? [英] IOS Parses PFLoginViewController didLoginUser Delegate is not being called when logging in via Facebook, why?

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

问题描述

这是一个非常奇怪的问题,因为在我更新到 Xcode 6 和 iOS 8 之前,我的 Facebook 登录可以正常工作.更奇怪的是,Twitter 运行良好,但 Facebook 没有调用 didLogin 回调.

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.

这是我在 AppDelegate 中所做的:

Here is what I am doing in my AppDelegate:

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

然后我设置了 Facebook &application:didFinishLaunchingWithOptions:

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];

在设置完这些之后,我像这样设置了我的 rootViewController:

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];

在我的 ConfigViewControllerviewDidAppear 中,我做了以下检查:

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];

此时如果用户没有登录,presentLoginViewControllerAnimated会发生以下情况:

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];

这里展示了 loginViewController.如果用户点击推特按钮,他将毫无问题地登录.然而,如果点击 Facebook 按钮,Facebook 确认屏幕会出现,我点击确定,然后它返回到我的 loginViewController.我需要调用它:

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

这样我就可以关闭 loginViewController 并执行任何其他操作.知道为什么会发生这种情况吗?

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

再说一次,为什么 loginViewController:didLogInUser: 委托没有被 Facebook 调用?

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

非常感谢任何帮助!

经过大量测试和许多头痛,这里是最新的.

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

如果我搞砸了 Info.plist 中的 URL Schemes,它就可以工作.我将名称从 URL Schemes 更改为 URL Scheme,但出现以下错误:

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

即使我收到此错误,我也会收到一个用于登录 FaceBook 的屏幕弹出窗口.我填写并进入,它有效,我可以使用 Facebook 登录.这看起来不太方便,但确实有效.

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.

我尝试过的其他测试/事情是下载 Facebook 应用程序并尝试登录、在没有 Facebook 应用程序的情况下登录(通过 safari)、在我的welcomeViewController 中而不是我的 AppDelegate 中实现委托,以及更新 Parse/Facebook SDK.

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.

我认为问题可能与打开另一个应用程序(例如 Facebook 或 safari)有关.我倾向于这个的原因是因为 Twitter 屏幕是一个模态弹出视图,它可以正常工作.当 Facebook 给我这个错误时,它不会切换到 safari 或 Facebook 应用程序,而是显示一个模态弹出登录并且它工作正常.这让我相信问题与切换应用程序和未正确接收回调有关.

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.

非常感谢 Matt Tang 为我指明了正确的方向.

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

推荐答案

结果是我不小心删除/注释掉了这 3 个回调的部分,这就是问题的根源.最后,我的解决方案是实现 application:handleOpenURL:application:openURL:sourceApplication:annotation:

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]];
}

并取消注释此行:

[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];

我在这次回调中的内容:

Which I had inside of this call back:

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

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

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