iOS版/斯威夫特:PFFacebookUtils.logInWithPersmissions返回nil用户和错误 [英] iOS/Swift: PFFacebookUtils.logInWithPersmissions returns nil user and error

查看:163
本文介绍了iOS版/斯威夫特:PFFacebookUtils.logInWithPersmissions返回nil用户和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我通过解析的PFFacebookUtil类登录用户。如果用户在手机上存在(即登录到FB在设置> Facebook的),然后按预期工作的一切。

In my app, I login users via Parse's PFFacebookUtil class. If the user exists on the phone (i.e. logged into FB in Settings>Facebook), then everything works as expected.

但如果他们的不通过设置登录,则该用户被带到一个Web视图登录。用户将在他们的凭据后,返回块应该得到一个用户或一个错误,但在这种情况下的用户和错误是零。

But if they're not logged in through settings, then the user is taken to a web view to log in. After the user puts in their credentials, the return block should receive a user or an error, but in this case both user and error is nil.

    let permissionsArray = ["user_about_me", "email"];
    PFFacebookUtils.logInWithPermissions(permissionsArray, block: {
        (user: PFUser!, error: NSError!) -> Void in
        if user != nil {
              //successful login
        } else if error != nil{
              //unsuccessful login 
        } else {
              //this is what I get
        }
    }

我们目前正在运行1.4.2解析

We are currently running Parse 1.4.2

推荐答案

现在的问题是,我没有在AppDelegate中调用调用FBAppCall.handleOpenURL():

The problem is that I wasn't calling FBAppCall.handleOpenURL() in the AppDelegate call:

application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) 

当我从一个网络身份验证回来。如果不调用FBAppCall.handleOpenURL(),分析认为,我们取消了我们的认证。解析文档指出用户和错误都是零 - 如果用户切换回应用程序取消认证

when I came back from a web auth. By not calling FBAppCall.handleOpenURL(), Parse thinks that we canceled our authentication. Parse documentation states that "user and error are both nil - if the user cancelled authentication by switching back to the application."

此方法应该调用FBAppCall.handleOpenURL通过认证回到应用程序。以我为例,我也是用这个呼吁深层链接,我没有正确处理逻辑。我本来是检查sourceApplication对象,看它是否是com.facebook.Facebook。如果它返回true,那么我叫FBAppCall.handleOpenURL()。当我今天调试它,我注意到源应用程序实际上是com.apple.mobilesafari。 检查sourceApplication不反正检查(尝试类似的url.host)最好的东西,但在这种情况下,这是问题。

This method is supposed to call FBAppCall.handleOpenURL to pass the authentication back to the app. In my case I was also using this call for deep linking and I didn't handle the logic properly. I originally was checking the sourceApplication object to see if it was "com.facebook.Facebook". If it returned true, then I called FBAppCall.handleOpenURL(). When I debugged it today, I noticed the source application is actually "com.apple.mobilesafari". Checking sourceApplication is not the best thing to check anyway (try something like the url.host), but in this case, that was the issue.

下面是固定的code片断:

Here's the fixed code snippet:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) {
    if (url.host == DEEP_LINKING_HOST) {
       //Deep linking code here...
    } else if sourceApplication == "com.apple.mobilesafari" {
       return FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication, withSession: PFFacebookUtils.session())
   }
}

这里的关键是,我没有打电话FBAppCall.handleOpenURL()。因此,应用程序认为我取消了登录,给了我一个零用户和错误。

The point here is that I wasn't calling FBAppCall.handleOpenURL(). As a result, the app thought that I canceled the login and gave me a nil user and error.

这篇关于iOS版/斯威夫特:PFFacebookUtils.logInWithPersmissions返回nil用户和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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