Search code examples
facebookfacebook-loginfacebook-ios-sdkfacebook-sdk-4.0

requestNewReadPermissions equivalent on Facebook iOS SDK v4


I'm having trouble finding the requestNewReadPermissions equivalent after upgrading to Facebook iOS SDK 4.x from 3.x. How do I force the system to re-ask for some permissions that user has not granted?


Solution

  • You need to check the current accesstoken's permissions for the one that you will require to launch a feature, and launch the permission request if the permission is missing:

    if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
      // HERE you implement the feature that requires publish actions.
    } else {
      FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
      [loginManager logInWithPublishPermissions:@[@"publish_actions"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        //TODO: if the user granted the permission, launch the feature. If not, fail gracefully.
      }];
    }