iOS/Swift:PFFacebookUtils.logInWithPermissions 返回 nil 用户和错误 [英] iOS/Swift: PFFacebookUtils.logInWithPermissions returns nil user and error

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

问题描述

在我的应用程序中,我通过 Parse 的 PFFacebookUtil 类登录用户.如果用户存在于手机上(即在设置">Facebook"中登录 FB),那么一切都会按预期进行.

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.

但如果他们未通过设置登录,则用户将进入网络视图进行登录.在用户输入凭据后,返回块应接收用户或一个错误,但在这种情况下用户和错误都是零.

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

我们目前正在运行 Parse 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(),Parse 认为我们取消了身份验证.解析文档指出用户和错误都为零 - 如果用户通过切换回应用程序取消身份验证."

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.

这是固定的代码片段:

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().结果,应用以为我取消了登录,给了我一个nil用户和错误.

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/Swift:PFFacebookUtils.logInWithPermissions 返回 nil 用户和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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