Imoox Studio Imoox Studio - 4 months ago 59
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 FacebookSignInProvider.java class that is included with the Android package and modify the Facebook loginWithReadPermissions function as such:

LoginManager.getInstance().logInWithReadPermissions(signInActivity,
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?

Regards.

Answer

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

AWSFacebookSignInProviderCustom.h

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

@interface AWSFacebookSignInProviderCustom : AWSFacebookSignInProvider <AWSSignInProvider>

+ (instancetype)sharedInstance;

@end

And then AWSFacebookSignInProviderCustom.m

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


@interface AWSFacebookSignInProviderCustom()

@property (strong, nonatomic) FBSDKLoginManager *facebookLogin;

@end

@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) {
                                                 NSLog(@"Error!");
                                             } else if (result.isCancelled)
                                             {
                                                 // Login canceled, do nothing
                                                 NSLog(@"Cancelled!");
                                             } else {
                                                 NSLog(@"FSBKDAccess Token: %@", [FBSDKAccessToken currentAccessToken]);
                                                 [[AWSFacebookSignInProvider sharedInstance] login];

                                             }
                                         }];
}

@end

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. :)

Comments