Created
October 31, 2015 17:22
-
-
Save mikekavouras/b35f9493091d5ffc54ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // ViewController.swift | |
| // FacebookTest | |
| // | |
| // Created by Michael Kavouras on 10/31/15. | |
| // Copyright © 2015 Michael Kavouras. All rights reserved. | |
| // | |
| import UIKit | |
| import ParseFacebookUtilsV4 | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view, typically from a nib. | |
| } | |
| @IBAction func facebookButtonTapped() { | |
| PFFacebookUtils.logInInBackgroundWithReadPermissions(["public_profile", "email", "user_friends"]) { | |
| (user: PFUser?, error: NSError?) -> Void in | |
| print(user) | |
| if let user = user { | |
| if user.isNew { | |
| print("User signed up and logged in through Facebook!") | |
| } else { | |
| let params = ["fields" : "id, name, email, gender"] | |
| let request = FBSDKGraphRequest(graphPath: "me", parameters: params) | |
| request.startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in | |
| print(result) | |
| PFUser.currentUser()?.setValue(result["name"], forKey: "name") | |
| PFUser.currentUser()?.setValue(result["gender"], forKey: "gender") | |
| PFUser.currentUser()?.setValue(result["email"], forKey: "email") | |
| PFUser.currentUser()?.saveInBackground() | |
| }) | |
| print("User logged in through Facebook!") | |
| } | |
| } else { | |
| print("Uh oh. The user cancelled the Facebook login.") | |
| } | |
| } | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment