Facebook SDK 4.7登录错误处理 [英] Facebook SDK 4.7 Login error handling

查看:160
本文介绍了Facebook SDK 4.7登录错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将FBSDK 4.7添加到我的快速应用程序中,当它打开Safari浏览器控制器登录时,我尝试点击完成,而不会在电子邮件/密码字段中输入任何内容,应用程序将会休息。它发出致命错误:意外发现零,同时解开一个可选的值



我如何处理这个错误?



当前登录代码:

 如果让fbLoginManager:FBSDKLoginManager = FBSDKLoginManager(){
fbLoginManager.logInWithReadPermissions([email],fromViewController:self,
处理程序:{(result:FBSDKLoginManagerLoginResult!,error:NSError!) - > Void in
if (error == nil){
let fbloginresult:FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains(email))
{
print(Logged in successfully )
self.getFBUserData()
//fbLoginManager.logOut()
}
}
else {
print(HELPPPPPPPP)
}
})
}


解决方案

p>不需要分配类型o f变量(结果,错误)



这是Facebook的工作代码4.7 SDK | Swift 2 | Xcode 7。

  @IBAction func btnFBLoginPressed(sender:AnyObject){
let fbLoginManager:FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web
fbLoginManager.logInWithReadPermissions([email],fromViewController:self,handler:{(result,error) - > Void in
if(error == nil){
let fbloginresult:FBSDKLoginManagerLoginResult = result
如果fbloginresult.grantedPermissions!= nil {//这里我们必须检查该集合是否包含
if(fbloginresult.grantedPermissions.contains (email))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
}
})
}

func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken())!= nil){
FBSDKGraphRequest(graphPath:me :[fields:id,name,first_name,last_name,picture.type(large),email])。startWithCompletionHandler({(connection,result,error))>空虚
if(error == nil){
print(result)
}
})
}
}

我们必须检查 approvedPermissions 设置 nil

  if fbloginresult.grantedPermissions!= nil {//这里我们必须检查该集合是否包含


I added FBSDK 4.7 to my swift app and when it opens the safari view controller to login, and I try to tap "Done" without inputting anything into the email/password fields, the app breaks. It spits out "fatal error: unexpectedly found nil while unwrapping an Optional value"

How do I handle this error?

Current login code:

if let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager(){
fbLoginManager.logInWithReadPermissions(["email"],fromViewController:self,
handler:{(result:FBSDKLoginManagerLoginResult!,error:NSError!) -> Void in
if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result
            if(fbloginresult.grantedPermissions.contains("email"))
            {
                print("Logged in successfully")
                self.getFBUserData()
                //fbLoginManager.logOut()
            }
        }
        else{
            print("HELPPPPPPPPPP")
        }   
     })
   }

解决方案

No need to assign the types of variable (result, error) :

Here is working code with Facebook 4.7 SDK | Swift 2 | Xcode 7.

@IBAction func btnFBLoginPressed(sender: AnyObject) {
    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web
    fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in
        if (error == nil){
            let fbloginresult : FBSDKLoginManagerLoginResult = result
            if fbloginresult.grantedPermissions != nil { //Here we have to check that the set contains value or not
                if(fbloginresult.grantedPermissions.contains("email"))
                {
                    self.getFBUserData()
                    fbLoginManager.logOut()
                }
            }
        }
    })
}

func getFBUserData(){
    if((FBSDKAccessToken.currentAccessToken()) != nil){
        FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
            if (error == nil){
                print(result)
            }
        })
    }
}

We have to check the grantedPermissions's Set is nil or not.

if fbloginresult.grantedPermissions != nil { //Here we have to check that the set contains value or not

这篇关于Facebook SDK 4.7登录错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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