Minkle Garg
Minkle Garg

Reputation: 1395

allow Facebook profile permissions

I want to implement the same Facebook authentication concept as in the friend smasher game.

In this If user is logged in on facebook via iOS facebook app then it only asks the user for accessing basic profile info. From above link there are steps to implement this concept in friend smasher game. I want to add this in my native app. But unable to know how to do this. If any one has knowledge about this please help me out. I would be very thankful to you.

Upvotes: 3

Views: 380

Answers (1)

rgomesbr
rgomesbr

Reputation: 242

When logging in, using:

NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"email",
                                nil];

// Attempt to open the session. If the session is not open, show the user the Facebook login UX
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:true completionHandler:^(FBSession *session,
                                                 FBSessionState status, 
                                                 NSError *error)  

If your "permissions" array is nil, it only requests the Basic access to the user profile. If you need other permissions, just add the wanted ones on the permissions array. The valid values can be found here: https://developers.facebook.com/docs/howtos/ios-6/, like "email", "user_birthday", "user_location", "user_about_me" etc.

Note that when logging in / requesting Read Permissions you CANNOT requests for publishing permissions. That must be performed later, after logging in. You can check if the user already has the requested permission (as the Publish one) and, if he/she has it, publish the content; if not, request it:

if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
    // If the user doesn't have the publishing permission, tries to request it befor sharing

    [FBSession.activeSession
     requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
     defaultAudience:FBSessionDefaultAudienceFriends
     completionHandler:^(FBSession *session, NSError *error) {
         if (!error) {
             // Tries to share the content again, assuming we now have the permission
             (...)
         } else {
             // Couldn't get the required Permissions
         }
     }];

} else {
    // If the user already have the permissions, tries to publish the content
    (...)
}

More info about publishing content, look up "requestNewPublishPermissions" here: https://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/publish-open-graph-story/

Upvotes: 3

Related Questions