ios - Parse: Facebook login not creating new PFUser -
i've been trying integrate facebook login , parse, new pfuser created upon logging in. have created facebook login button, , when press standard facebook login/asking permissions screen appears. when accept login redirected initial screen, , log shows user has cancelled facebook login. when check data on parse website, there no pfusers.
as far can tell have followed exact instructions laid out parse (https://parse.com/docs/ios/guide#users) , facebook.(https://developers.facebook.com/docs/ios/getting-started). using xcode 6.3.2. have added integrated parse (parsefacebookutilsv4 v1.7 & parseui v1.1) , facebook (fbsdkcorekit v4.2 &fbsdkloginkit v4.2) in cocoapods, , have linked following libraries:
libsqlite3.dylib libz.dylib accounts.framework audiotoolbox.framework cfnetwork.framework coregraphics.framework corelocation.framework corelocation.framework mobilecoreservice.framework quartzcore.framework security.framework social.framework storekit.framework systemconfiguration.framework libpods-xxx.a (being name of project) my code follows:
//appdelegate.swift import uikit @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? //-------------------------------------- // mark: - uiapplicationdelegate //-------------------------------------- func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { parse.setapplicationid("xxxxxxxx", clientkey: "xxxxxxxxxx") pffacebookutils.initializefacebookwithapplicationlaunchoptions(launchoptions) return fbsdkapplicationdelegate.sharedinstance().application(application, didfinishlaunchingwithoptions: launchoptions) } } func application( application: uiapplication, openurl url: nsurl, sourceapplication: string, annotation: anyobject?) -> bool { return fbsdkapplicationdelegate.sharedinstance().application(application, openurl: url, sourceapplication: sourceapplication, annotation: annotation) } //facebook analytics func applicationdidbecomeactive(application: uiapplication!) { fbsdkappevents.activateapp() } and view controller in login in placed:
//onboardingrootviewcontroller.swift import foundation import uikit class onboardingrootviewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } @ibaction func fbloginclick(sender: anyobject) { var permissions = ["public_profile", "email", "user_likes"] pffacebookutils.logininbackgroundwithreadpermissions(permissions) { (user: pfuser?, error: nserror?) -> void in if let user = user { if user.isnew { println("user signed , logged in through facebook!") } else { println("user logged in through facebook!") } } else { println("uh oh. user cancelled facebook login.") } } } } so, can of help? again, facebook login @ least appears work, when ibaction fbloginclick invoked, "uh oh. user cancelled facebook login." message shown in log, , no new pfuser created in parse. i've seen multiple other similar questions, none real answers i'm sure answer question appreciated many, using exact code shown in login tutorials created parse , facebook!
edit: if no 1 able help, i'd still appreciate following: i've been told should check error message returned logininbackgroundwithreadpermissions, unfortunately without further explanation. person referring "uh oh. user cancelled facebook login." message, or possible retrieve information through nserror?
edit #2: added following line of code see nserror returns: println("write failure: (error?.localizeddescription)")
and following message in log: uh oh. user cancelled facebook login. write failure: nil
so guess didn't me further...
edit #3: seriously, i'll paypal 10$ can me
this code work if set frameworks correctly , follow steps of parse's facebook setup guide (https://parse.com/docs/ios/guide#users-facebook-users). make sure syntax same functions have , try getting rid of unnecessary code isn't included below.
appdelegate.swift
import uikit import coredata import parse @uiapplicationmain class appdelegate: uiresponder, uiapplicationdelegate { var window: uiwindow? func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject: anyobject]?) -> bool { //x's replace actual parse information parse.setapplicationid("xxxxxxxxxxxxxxxxxxxxxx", clientkey: "xxxxxxxxxxxxxxxxxxxxxx") pfanalytics.trackappopenedwithlaunchoptions(launchoptions) pffacebookutils.initializefacebookwithapplicationlaunchoptions(launchoptions) return fbsdkapplicationdelegate.sharedinstance().application(application, didfinishlaunchingwithoptions: launchoptions) } 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) { fbsdkappevents.activateapp() } /* func application(application: uiapplication, url: nsurl, sourceapplication: nsstring, annotation: anyobject) -> bool { return fbsdkapplicationdelegate.sharedinstance().application( application, openurl: url, sourceapplication: sourceapplication string, annotation: annotation) }*/ func application(application: uiapplication, openurl url: nsurl, sourceapplication: string?, annotation: anyobject?) -> bool { return fbsdkapplicationdelegate.sharedinstance().application(application, openurl: url, sourceapplication: sourceapplication, annotation: annotation) } func applicationwillterminate(application: uiapplication) { // called when application terminate. save data if appropriate. see applicationdidenterbackground:. // saves changes in application's managed object context before application terminates. self.savecontext() } viewcontroller.swift
import uikit class viewcontroller: uiviewcontroller { override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } let permissions = [ "email","user_birthday", "public_profile", "user_friends"] @ibaction func loginbuttonpressed(sender: anyobject) { pffacebookutils.logininbackgroundwithreadpermissions(permissions) { (user: pfuser?, error: nserror?) -> void in if let user = user { if user.isnew { println("user signed , logged in through facebook!") } else { println("user logged in through facebook!") } } else { println("uh oh. user cancelled facebook login.") } } } } the @ibaction simple uibutton put in center of blank viewcontroller in main.storyboard
objective-c bridging header:
#import <fbsdkcorekit/fbsdkcorekit.h> #import <parsefacebookutilsv4/pffacebookutils.h> #import <parse/parse.h> hope solves problem!
Comments
Post a Comment