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

查看:125
本文介绍了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.

但是,如果未通过设置登录,则会将用户带到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(),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().结果,该应用程序以为我取消了登录并给了我零用户和错误.

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天全站免登陆