swift - Making Facebook login with new Firebase -
i want implement facebook login new firebase , can't right.
i added cocoapods, went through docs both firebase , facebook. when open simulator this: http://d.pr/i/bvpz/4ibjkx9t
this viewcontroller:
import uikit import fbsdkcorekit import fbsdkloginkit import firebase class viewcontroller: uiviewcontroller, fbsdkloginbuttondelegate { let loginbutton: fbsdkloginbutton = fbsdkloginbutton() override func viewdidload() { super.viewdidload() // optional: place button in center of view. loginbutton.center = self.view.center loginbutton.readpermissions = ["public_profile", "email", "user_friends"] loginbutton.delegate = self view!.addsubview(loginbutton) } func loginbutton(loginbutton: fbsdkloginbutton!, didcompletewithresult result: fbsdkloginmanagerloginresult!, error: nserror?) { if let error = error { print(error.localizeddescription) return } print("user logged in") } func loginbuttondidlogout(loginbutton: fbsdkloginbutton!) { print("user logged out") } func loginbuttonwilllogin(loginbutton: fbsdkloginbutton!) -> bool { print("user login") return true } }
this appdelegate:
import uikit import firebase import fbsdkloginkit @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { firapp.configure() fbsdkapplicationdelegate.sharedinstance().application(application, didfinishlaunchingwithoptions: launchoptions) return true } func application(application: uiapplication, openurl url: nsurl, sourceapplication: string?, annotation: anyobject) -> bool { let handled: bool = fbsdkapplicationdelegate.sharedinstance().application(application, openurl: url, sourceapplication: sourceapplication, annotation: annotation) return handled } func applicationwillresignactive(application: uiapplication) { // sent when application move active inactive state. can occur types of temporary interruptions (such incoming phone call or sms message) or when user quits application , begins transition background state. // use method pause ongoing tasks, disable timers, , throttle down opengl es frame rates. games should use method pause game. } func applicationdidenterbackground(application: uiapplication) { // use method release shared resources, save user data, invalidate timers, , store enough application state information restore application current state in case terminated later. // if application supports background execution, method called instead of applicationwillterminate: when user quits. } func applicationwillenterforeground(application: uiapplication) { // called part of transition background inactive state; here can undo many of changes made on entering background. } func applicationdidbecomeactive(application: uiapplication) { // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface. fbsdkappevents.activateapp() } func applicationwillterminate(application: uiapplication) { // called when application terminate. save data if appropriate. see applicationdidenterbackground:. } }
add else loginbutton:didcompletewithresult method. completes login on firebase side. although, wouldn't explain current error.
let credential = firfacebookauthprovider.credentialwithaccesstoken(fbsdkaccesstoken.currentaccesstoken().tokenstring) firauth.auth()?.signinwithcredential(credential, completion: { (user, error) in if let error = error { print(error) } else { self.signedin(user) } })
as current error, did add url schemes, app id, , app name facebook provides in developer console when create app info.plist? seems me that failing. app needs have permission facebook login.
Comments
Post a Comment