btn_Facebook.addTarget (self, action: #selector (handleCustomFBLogin), для: .touchUpInside)
@objc func handleCustomFBLogin(sender:UIButton!){
FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self) { (result, err) in
if(err != nil){
print("Custom FB Login Failed")
return
}
//print(result?.token.tokenString)
self.showEmailAddress()
}
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!){
if(error != nil){
print(error)
return
}
print("Successfully Logged in using facebook")
showEmailAddress()
}
func showEmailAddress(){
let accesstoken = FBSDKAccessToken.current();
guard let accessTokenString = accesstoken?.tokenString else {return}
FBSDKGraphRequest(graphPath: "/me", parameters: ["fields" : "id, name, first_name, last_name, email, birthday, picture"]).start { (connection, result, err) in
if(err != nil){
print("Failed to start GraphRequest", err ?? "")
return
}
print(result ?? "")
if(result != nil){
self.sendDetailsForFacebookLogin(result: result as! NSDictionary)
}else{
MyCustomAlert.sharedInstance.ShowAlert(vc: self, myTitle: StringClass.sharedInstance.lcStr_loginfailedcaps, myMessage: StringClass.sharedInstance.lcStr_plsTryAgain)
}
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!){
print("Logged out of Facebook")
}
func sendDetailsForFacebookLogin(result:NSDictionary){
print(result)
}