Imoox Studio Imoox Studio - 1 year ago 148
iOS Question

Requesting additional Facebook Login permissions with AWS Mobile iOS SDK

I am using AWS Mobile for iOS and I would like to request additional permissions from the Facebook Login (such as user_birthday and other Facebook permissions).

On the Android package you can download from the AWS Mobile HUB it's as simple as modifying the class that is included with the Android package and modify the Facebook loginWithReadPermissions function as such:

Arrays.asList("public_profile", "email", "user_birthday"));

But I am also using the iOS Obj-C source package you obtain by building with the AWS Mobile HUB, and only the header files are provided, so it is not possible to modify such implementation.

Any tips?


Answer Source

I ended up solving this issue by overwriting the AWSFacebookSignInProvider class, so I ended up with a header and implementation files as such:


#import <Foundation/Foundation.h>
#import <AWSMobileHubHelper/AWSSignInProvider.h>
#import <AWSMobileHubHelper/AWSFacebookSignInProvider.h>

@interface AWSFacebookSignInProviderCustom : AWSFacebookSignInProvider <AWSSignInProvider>

+ (instancetype)sharedInstance;


And then AWSFacebookSignInProviderCustom.m

#import "AWSFacebookSignInProviderCustom.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

@interface AWSFacebookSignInProviderCustom()

@property (strong, nonatomic) FBSDKLoginManager *facebookLogin;


@implementation AWSFacebookSignInProviderCustom

+ (instancetype)sharedInstance {
    static AWSFacebookSignInProviderCustom *_sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [AWSFacebookSignInProviderCustom new];

    return _sharedInstance;

- (void)login

    if (!self.facebookLogin)
        self.facebookLogin = [FBSDKLoginManager new];

    [self.facebookLogin logInWithReadPermissions:@[@"public_profile", @"email", @"user_birthday"]
                                         handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
                                             if (error) {
                                             } else if (result.isCancelled)
                                                 // Login canceled, do nothing
                                             } else {
                                                 NSLog(@"FSBKDAccess Token: %@", [FBSDKAccessToken currentAccessToken]);
                                                 [[AWSFacebookSignInProvider sharedInstance] login];



So basically that overrides the login button permissions adding any custom permissions you might want. Afterwards, it just calls the standard AWSFacebookSignInProvuder login method to complete things as usual.

That did the trick for me. I hope it can help other people out. :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download