jona jürgen
jona jürgen

Reputation: 1839

iOS FBSDK check permissions in Swift

I try to check if a logged in FB User has the needed permissions. I try it like this in Swift:

let permissions : Set<String> = ["public_profile", "user_friends"];
NSLog("Contains Permissions:%@",FBSDKAccessToken.currentAccessToken()
        .permissions.contains(permissions));

NSLog always returns 0, even though the permissions in the currentAccessToken and in the permissions variable are equal to each other.

My guess is, that I am doing something wrong while comparing the 2 Set´s, I hope some of you can help ;)

Upvotes: 1

Views: 3953

Answers (1)

Maulik shah
Maulik shah

Reputation: 1704

for checking facebook permission..& give a permission

 var login: FBSDKLoginManager = FBSDKLoginManager()
login.logInWithReadPermissions(["public_profile", "user_friends"], handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in

  if (error != nil)
  {
        //Process error
   }
   else if result.isCancelled
   {
        //Handle cancellations
   }
  else
  {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if result.grantedPermissions.contains("user_friends"){
            //Do work
   }
     }
   })

If you want to more information about facebook with swift then read follow link...

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

May be this will help you.

Upvotes: 3

Related Questions