-
Notifications
You must be signed in to change notification settings - Fork 0
/
fb login
39 lines (35 loc) · 1.91 KB
/
fb login
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
========== Login with fb====================
if strFbAccessToken.isEmpty
{
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logIn(withReadPermissions: ["email"]) { (result, error) -> Void in
if (error == nil){
// let fbloginresult : FBSDKLoginManagerLoginResult = result!
if((FBSDKAccessToken.current()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
//everything works print the user data
//print(result ?? <#default value#>)
print(result as Any)
strFbAccessToken = FBSDKAccessToken.current().tokenString
self.btnFB.setTitle("Logout", for: .normal)
self.btnFB.setTitleColor(UIColor.white, for: .normal)
self.btnFB.backgroundColor = UIColor(hex: "344086")
self.btnFB.setImage(nil, for: .normal)
self.btnFB.layer.cornerRadius = 5.0
}
})
}
}
}
}
else
{
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logOut()
strFbAccessToken=""
btnFB.backgroundColor = UIColor.clear
btnFB.setTitle(nil, for: .normal)
btnFB.setImage(UIImage(named:"Fb_login.png"), for: .normal)
btnFB.layer.cornerRadius = 0
}