0

Where is the latest Facebook Swift Documentation. I can't get the FB Login Dialog to show up. The call to loginWithReadPermissions never returns?

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit


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

            let loginManager = FBSDKLoginManager()
            loginManager.logInWithReadPermissions(["basic_info", "email", "user_likes"], fromViewController: self.parentViewController, handler: { (result, error) -> Void in
                if error != nil {
                    print(FBSDKAccessToken.currentAccessToken())
                } else if result.isCancelled {
                    print("Cancelled")
                } else {
                    print("LoggedIn")
                }
            })
        }
justdan0227
  • 1,374
  • 18
  • 48

2 Answers2

2

You code should work if you exclude "user_likes" from permissions. From facebook docs: If your app asks for more than public_profile, email and user_friends, Facebook must review it before you release it. Learn more about the review process and what's required to pass review. https://developers.facebook.com/docs/facebook-login/permissions/v2.5#reference-user_likes

Another problem may be that you have not set correctly the FacebookSDK in your project. See this tutorial: https://developers.facebook.com/docs/ios/getting-started/

Iurie Manea
  • 1,217
  • 10
  • 16
  • Thanks Lurie, That's the doc's I was looking at, however there is nothing to address Swift2. I took everything out but "email" and still does not return. What all Swift2 needs to be in AppDelegate.swift. Maybe I'm missing something there. I have all in the plist that is needed. – justdan0227 Oct 15 '15 at 00:20
  • Still not sure why logInWithReadPermissions is not working, however if I changed the call to `let loginView : FBSDKLoginButton = FBSDKLoginButton() self.view.addSubview(loginView) loginView.center = self.view.center loginView.readPermissions = ["public_profile", "email", "user_friends"] loginView.delegate = self` I at least get the login dialog when I press the button. – justdan0227 Oct 15 '15 at 15:58
0

So the answer is to use FBSDKLoginButton with the following

In the class declaration of the viewController

import FBSDKCoreKit
import FBSDKLoginKit
class ViewController: UIViewController, FBSDKLoginButtonDelegate

Then show the FBLogin Button with

        // Setup the FB Login/Logout Button  FB will take care of the
        // verbiage based on the current access token

        let loginView : FBSDKLoginButton = FBSDKLoginButton()
        self.view.addSubview(loginView)
        loginView.center = self.view.center
        loginView.readPermissions = ["public_profile", "email", "user_friends"]
        loginView.delegate = self

        // If we have an access token, then let's display some info

        if (FBSDKAccessToken.currentAccessToken() != nil)
        {
            // Display current FB premissions
            print (FBSDKAccessToken.currentAccessToken().permissions)

            // Since we already logged in we can display the user datea and taggable friend data.
            self.showUserData()
            self.showFriendData()
        }

Show the users info with

 func showUserData()
    {
        let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "id, name, gender, first_name, last_name, locale, email"])
        graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

            if ((error) != nil)
            {
                // Process error
                print("Error: \(error)")
            }
            else
            {
                let userName : NSString = result.valueForKey("name") as! NSString
                print("User Name is: \(userName)")

                if let userEmail : NSString = result.valueForKey("email") as? NSString {
                    print("User Email is: \(userEmail)")
                }
            }
        })
    }

And to display the taggable friends

func showFriendData()
    {
        let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me/taggable_friends?limit=999", parameters: ["fields" : "name"])
        graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in

            if ((error) != nil)
            {
                // Process error
                print("Error: \(error)")
            }
            else
            {
                if let friends : NSArray = result.valueForKey("data") as? NSArray{
                    var i = 1
                    for obj in friends {
                        if let name = obj["name"] as? String {
                            print("\(i) " + name)
                            i++
                        }
                    }
                }
            }
        })
    }
justdan0227
  • 1,374
  • 18
  • 48