ios - Facebook Login without FBSDKLoginButton in Swift -
i trying add facebook login app. using fbsdkloginbutton comes own button , once login turns logout. don't want that. need add own button view. , in button's @ibaction want facebook login take place. code using is
class viewcontroller: uiviewcontroller,fbsdkloginbuttondelegate { override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. if (fbsdkaccesstoken.currentaccesstoken() != nil) { // user logged in, work such go next view controller. } else { let loginview : fbsdkloginbutton = fbsdkloginbutton() self.view.addsubview(loginview) loginview.center = self.view.center loginview.readpermissions = ["public_profile", "email", "user_friends"] loginview.delegate = self } } func loginbutton(loginbutton: fbsdkloginbutton!, didcompletewithresult result: fbsdkloginmanagerloginresult!, error: nserror!) { println("user logged in") if ((error) != nil) { // process error } else if result.iscancelled { // handle cancellations } else { returnuserdata() // if ask multiple permissions @ once, // should check if specific permissions missing if result.grantedpermissions.contains("email") { // work } } } func loginbuttondidlogout(loginbutton: fbsdkloginbutton!) { println("user logged out") } func returnuserdata() { let graphrequest : fbsdkgraphrequest = fbsdkgraphrequest(graphpath: "me", parameters: nil) graphrequest.startwithcompletionhandler({ (connection, result, error) -> void in if ((error) != nil) { // process error println("error: \(error)") } else { println("fetched user: \(result)") let username : nsstring = result.valueforkey("name") as! nsstring println("user name is: \(username)") let useremail : nsstring = result.valueforkey("email") as! nsstring println("user email is: \(useremail)") } }) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
how customise , achieve need. in advance.
fbsdkloginmanager can used if fb login handled via custom button.
for more info, can check this.
Comments
Post a Comment