Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

iphone - IOS Swift and Facebook SDK

Let me apologize first, just learning swift, so I am not 100% on what I am doing. I have found many tutorials on integrating a facebook login in swift and have what appears to be working in the app, but it seems my delegates are never getting called. What I expect to happen is when a user logins 2 things should happen.

1) The login button for facebook should change to a logout button.
2) A console command should print that I logged in, and ultimately user information.

ViewController Class is:

class ViewController: UIViewController,FBLoginViewDelegate {

    @IBOutlet var fbLoginView : FBLoginView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]
    }

    // Facebook Delegate Methods

    func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
        println("User Logged In")
        println("This is where you perform a segue.")
    }

    func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
        println("User Name: (user.name)")
    }

    func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
        println("User Logged Out")
    }

    func loginView(loginView : FBLoginView!, handleError:NSError) {
        println("Error: (handleError.localizedDescription)")
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

AppDelegate sections are:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    FBLoginView.self
    FBProfilePictureView.self

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool {

        var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
        return wasHandled

    }

    return true
}

As you can see, most of this is straight from the tutorials but is not working correctly. I've got my info.plist configured, and the FBLoginView appears and goes thru the entire authentication, but nothing is printed to console and the button doesn't change.
When I try to click it again, I get app already authorized, which should mean that the auth was successful, but nothing got triggered back in my app.

I feel confident that something is probably wrong with my appdelegate but being new to swift, I have no clue what..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Facebook as changed SDk. Please find the latest solution here

http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...