Emil David Emil David - 1 year ago 118
Swift Question

Facebook Permissions iOS

So I was fiddling around with Facebook's iOS SDK and with it I managed to allow the user to login into my app. I had a

setup on the storyboard that was of
class which according to this, its simply a subclass of
. I then created an
@IBOutlet weak var facebookLogInBtn: FBSDKLoginButton!
. Then I went forth to setup my permissions as such

override func viewDidLoad()

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

This works just fine and accomplishes my desired task and any extra permissions I require, I simply append them to the
array. But after some Googling, I found a bunch of sites which use the
along with the
instead. Take for instance this blog. Now my questions are:

  1. Is my way deemed acceptable or hacky? It works but I just want to be certain that I am following the standard procedures.

  2. How does my way somehow tie into getting data through the Graph API? Because I am explicitly not declaring any
    objects. I simply added my button then implemented its
    and Voila! I am getting access. No need to parse any JSON data or anything.

  3. I also noticed that most of these sites never actually made any of their
    a class of
    . Could this be the reason why they have to handle everything 'manually'?

Any assistance will be greatly appreciated.

Answer Source

The way that I was doing is correct but I wasn't able to retrieve any user data with it. With FBSDKLoginManager object, Facebook handled everything for me and it would simply return the user's final response (agreed or not) but without any actual data I requested through my readPermissions array. For any data retrieval; and possibly even writes, I had to create a FBSDKGraphRequest object for it. In summary, I ended up letting Facebook handle the log in and log out with FBSDKLoginManager and upon success, I retrieved user data with FBSDKGraphRequest as shown below

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
    if error != nil
       print("Facebook Log In Failed")

    let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields" : "\(FacebookPermission.NAME), \(FacebookPermission.FIRST_NAME), \(FacebookPermission.LAST_NAME), \(FacebookPermission.EMAIL)"])

    graphRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result:AnyObject!, error: NSError!) in

        if error == nil
            print("Data retrieval was successful")
            print("Facebook Graph Request Error")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download