IOS Swift and Facebook SDK - ios

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..

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/

I would like to suggest you the cheking of these steps:
-in your VC class, import FacebookSDK statement and FBLoginViewDelegate ?
- your outlet should be:
//FB outlet
#IBOutlet var fbLoginView: FBLoginView
- in your AppDelegate.swift, also imported the FacebookSDK ?
- you have a func in a func in your AppDelegate.swift.It should be:
import FacebookSDK
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//FB implementation
FBLoginView.self
FBProfilePictureView.self
return true
}
//FB Method handles what happens after authentication
func application (application:UIApplication, openURL url:NSURL, sourceApplication:NSString?, annotation:AnyObject) -> Bool {
//test var
var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
// attempt to extract a token from the url
return wasHandled
}

Related

Calling delegate methods for Chartboost in IOS Swift

I've integrated Chartboost into my app and I am able to see ads, but I don't have a firm grasp of delegates and I am having trouble using the Chartboost provided code to cause actions to occur after an ad is viewed. My app delegate code is below (i replaced the actual appid and signature that I'm using):
class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
application.isStatusBarHidden = true
Chartboost.start(withAppId: "appID", appSignature: "appSignature", delegate: self)
Chartboost.cacheRewardedVideo(CBLocationHomeScreen)
Chartboost.cacheInterstitial(CBLocationHomeScreen)
func didDisplayInterstitial(_ location: String!){print("didDisplayI")}
func didCloseInterstitial(_ location: String!){print("didCloseI")}
func didDismissInterstitial(_ location: String!){print("didDismissI")}
return true
}
Then in my ViewController I have the following:
class CharacterCreationViewController: UIViewController, ChartboostDelegate {
weak var delegate: ChartboostDelegate?
Override func viewDidLoad() {
super.viewDidLoad()
Chartboost.setDelegate(self)
}
#IBAction func watchAd(_ sender: Any) {
Chartboost.showInterstitial(CBLocationLevelStart)
delegate?.didDismissInterstitial!(CBLocationLevelStart)
delegate?.didCloseInterstitial!(CBLocationLevelStart)
delegate?.didDisplayInterstitial!(CBLocationLevelStart)
}
The watchAd function is a button, and when I press it the ad runs, but none of the actions in the appDelegate file run once the ad is completed/dismissed/closed.
I've searched StackOverflow and the Chartboost help sections and messaged Chartboost support but I'm struggling to find where I've gone wrong.

Calling segue with swift if user already logged in with facebook

I have been following this tutorial on how to make a facebook login with swift. http://letsbuildthatapp.com/2016/03/26/swift-facebook-login-sdk-and-getting-users-email/
But, when i dismiss the app by double clicking on home button and sliding up the application I see my login screen with one difference. Button's text has changed to logout.
What i want to do is automatically skipping that login page and performing this segue: self.performSegueWithIdentifier("redirectAfterLogin", sender: self)
I come across this article yet I couldn't fix the issue by myself and now I'm little bit confused.
How to check if user is logged in with FBSDKLoginKit in iOS?
Below you can see my AppDelegate.swift and LoginVC.swift files. How can I fix this?
AppDelegate.swift
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CNPPopupControllerDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
LoginVC.swift
import UIKit
import KASlideShow
class LoginVC: UIViewController, KASlideShowDelegate, FBSDKLoginButtonDelegate {
let loginButton: FBSDKLoginButton = {
let button = FBSDKLoginButton()
button.readPermissions = ["email"]
return button
}()
override func viewDidLoad() {
super.viewDidLoad()
// do stuff here
view.addSubview(loginButton)
loginButton.center = view.center
loginButton.readPermissions = ["public_profile", "email", "user_friends"]
loginButton.delegate = self // Remember to set the delegate of the loginButton
if let token = FBSDKAccessToken.currentAccessToken() {
fetchProfile()
}
if FBSDKAccessToken.currentAccessToken() != nil {
print("1")
self.performSegueWithIdentifier("redirectAfterLogin", sender: self)
}
}
func fetchProfile(){
print("fetching profile..")
let params = ["fields": "email, first_name, last_name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: params).startWithCompletionHandler{ (connection, result, var error) -> Void in
if error != nil {
print (error)
return
}
if let email = result["email"] as? String {
print(email)
NSUserDefaults.standardUserDefaults().setObject(email, forKey: "email")
}
if let first_name = result["first_name"] as? String {
print(first_name)
NSUserDefaults.standardUserDefaults().setObject(first_name, forKey: "first_name")
}
if let last_name = result["last_name"] as? String {
print(last_name)
NSUserDefaults.standardUserDefaults().setObject(last_name, forKey: "last_name")
}
if let picture = result["picture"] as? NSDictionary, data=picture["data"] as? NSDictionary, url=data["url"] as? String {
print(url)
NSUserDefaults.standardUserDefaults().setObject(url, forKey: "url")
}
NSUserDefaults.standardUserDefaults().synchronize()
print(result) // this prints whole FBSDKGraphRequest API response
}
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
print("login completed")
fetchProfile()
self.performSegueWithIdentifier("redirectAfterLogin", sender: self)
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
}
func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
return true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
What you'll need to do is in appDelegate on
application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:
if let root = UIApplication.sharedApplication().windows[0].rootViewController as? UINavigationController {
if CONDITION {
root.viewControllers = [USER_HOMEPAGE]
} else {
root.viewControllers = [USER_LOGIN]
}
}

Facebook with Parse can't Login Swift 2.0

My app uses ParseSDK for creating Users and I want to implement simple Facebook login button in my application but I couldn't. I tried many times with FacebookSDK and ParseSDK Guides. But I failed. Could you look my codes and please tell me whats wrong ?
import UIKit
import CoreLocation
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseFacebookUtilsV4
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let locationManager = CLLocationManager()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Initialize Parse.
Parse.enableLocalDatastore()
Parse.setApplicationId(Constants.ParseAPIKey, clientKey: Constants.ParseClientKey)
PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
FBSDKAppEvents.activateApp()
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
}
There are the SDK Files.
There is the info.plist.
There is my LoginButton TableView Controller.swift file.
import UIKit
import Parse
import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit
import ParseFacebookUtilsV4
class UserProfileTableViewController: UITableViewController {
#IBOutlet weak var statusLabel: UILabel!
#IBOutlet weak var usernameTextField: UITextField!
#IBOutlet weak var passwordTextField: UITextField!
var user: User? {
if let currentUser = PFUser.currentUser() {
return User(user: currentUser)
}
return nil
}
override func viewWillAppear(animated: Bool) {
self.configureStatusLabel()
}
func configureStatusLabel() {
if user != nil { // User Logged In !
if let name = user?.name,
let surname = user?.surname {
statusLabel.text = "Welcome, \(name) \(surname)"
}
} else {
self.statusLabel.text = "You are not logged in"
}
}
func face() {
let permissions = ["public_profile", "email", "user_friends"]
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions) { (user: PFUser?, error: NSError?) -> Void in
if error == nil {
print(user)
} else {
print("fail")
}
}
}
#IBAction func loginWithFacebook() {
face()
}
#IBAction func logoutButton() {
PFUser.logOut()
self.configureStatusLabel()
}
}
When I click the my Login with Facebook Button. Safari opens and connects to the facebook like this.
When I tap the Tamam which mean is OK button in this page. It returns my application with this error:
2015-09-15 14:06:49.975 VetMapp[2233:81246]
+[PFUser logInWithAuthTypeInBackground:authData:]:
unrecognized selector sent to class 0x109fd8470
2015-09-15 14:06:49.980 VetMapp[2233:81246]
[Error]: Caught "NSInvalidArgumentException"
with reason "+[PFUser logInWithAuthTypeInBackground:authData:]:
unrecognized selector sent to class 0x109fd8470":
(
First of all thank your for reading this and I really appreciated help for solve this problem. Thank you !
For Swift 2.0, you have to "whitelist" FB servers. You have to make a few changes to the Info.plist file and all will be working again. If you are using pods, make sure you update them as well.
Follow this link to see what you need to add in the plist file:
https://developers.facebook.com/docs/ios/ios9

Facebook Login Swift don't works On Device (But do on IOS Simulator)

I configure in my app authentication with Facebook Login in Swift 2.
Everything works perfectly on IOS Simulator (IOS 8 and 9): User click on "Login with Facebook", then a safari page opening, then authentication continue and finally user is logged correctly:
But when I try on my Ipod Touch, it ALWAYS block and fail on this message (Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can), and my user is not logged:
I have tried a lot of things :
Change Facebook SDK (I have tried to 4.0 Facebook SDK)
Upgrade my ipod touch on IOS 8.4, next on IOS 9.
Downgrade Xcode 7beta to XCode 6
Remove Facebook App on Ipod Touch and Reinstall it
But still not working.. Any help would be appreciated!
Here is my code:
AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//For Facebook Login
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)
}
ViewController.swift
class ViewController: UIViewController, FBSDKLoginButtonDelegate {
#IBOutlet weak var signInButtonFB: FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
//Configure Facebook
signInButtonFB.readPermissions = ["public_profile", "email", "user_friends"]
signInButtonFB.delegate = self
//Configure Facebook SignIn
if (FBSDKAccessToken.currentAccessToken() != nil)
{
print("Logged in !")
}
else
{
print("not logged")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: Facebook
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
print("Début login Button")
if ((error) == nil)
{
print("Login Complete")
returnUserData()
}
else {
print ("Voici l'erreur:"+error.localizedDescription)
}
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
print("User Logged Out")
}
Looks like my app Facebook was still in development mode..
I forget to set "Contact Name" and allow my app to public access.
SETUP FOR FACEBOOK APP:
Go to : https://developers.facebook.com/apps/
My Apps -> Settings -> Basic -> Contact Email = Give email valid
My Apps -> Status and Review Tab -> "Do you want to make this app and all its live features available to the general public?" = Yes
I meet the same problem. I fixed by checking the login permissions.
Also check again the spelling mistakes of the permission texts.
Make sure your permissions are all enabled on developer.facebook.com.

Parse: Facebook login not creating new PFUser

I've been trying to integrate Facebook login and Parse, so that a new PFUser is created upon logging in. I have created a Facebook login button, and when I press it the standard Facebook login/asking for permissions screen appears. When I accept the login I am redirected back to the initial screen, and the log shows that the user has cancelled the Facebook login. When I check my data on the Parse website, there are no PFUsers.
As far as I can tell I have followed the exact instructions laid out by Parse (https://parse.com/docs/ios/guide#users) and Facebook.(https://developers.facebook.com/docs/ios/getting-started). I am using XCode 6.3.2. I have added integrated Parse (ParseFacebookUtilsV4 v1.7 & ParseUI v1.1) and Facebook (FBSDKCoreKit v4.2 &FBSDKLoginKit v4.2) in Cocoapods, and have linked the 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 the name of my project)
My code is as 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 the View controller in which the login in placed:
//OnboardingRootViewController.swift
import Foundation
import UIKit
class OnboardingRootViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be 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 up and logged in through Facebook!")
} else {
println("User logged in through Facebook!")
}
} else {
println("Uh oh. The user cancelled the Facebook login.")
}
}
}
}
So, can anyone be of any help? Again, the Facebook login at least appears to work, when the IBAction fbLoginClick is invoked, but the "Uh oh. The user cancelled the Facebook login." message is shown in the log, and no new PFUser is created in Parse. I've seen multiple other similar questions, but none with any real answers so I'm sure an answer to this question would be appreciated by many, especially as this is using the exact code shown in the login tutorials created by Parse and Facebook!
Edit: If no one is able to help, I'd still appreciate help with the following: I've been told that I should check which error message is returned by loginInBackgroundWithReadPermissions, unfortunately without further explanation. Was this person simply referring to the "Uh oh. The user cancelled the Facebook login." message, or is it possible to retrieve any information through the NSError?
Edit #2:
I added the following line of code to see what the NSError returns:
println("write failure: (error?.localizedDescription)")
And get the following message in the log:
Uh oh. The user cancelled the Facebook login.
write failure: nil
So I guess that didn't really get me any further...
Edit #3: Like seriously, I'll paypal 10$ to anyone that can help me
This code will work if you set up the frameworks correctly and follow the steps of Parse's Facebook setup guide (https://parse.com/docs/ios/guide#users-facebook-users). Make sure your syntax is the same as the functions I have and try getting rid of any unnecessary code that 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 my 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 the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the 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 as 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 the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}
ViewController.swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be 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 up and logged in through Facebook!")
} else {
println("User logged in through Facebook!")
}
} else {
println("Uh oh. The user cancelled the Facebook login.")
}
}
}
}
The #IBAction is for a simple UIButton I put in the center of the blank viewcontroller in my Main.storyboard
Objective-C Bridging Header:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <Parse/Parse.h>
Hope this solves your problem!

Resources