Skip to content

Instantly share code, notes, and snippets.

@jldavid
Created March 9, 2016 01:40
Show Gist options
  • Select an option

  • Save jldavid/b6d75a2b6d0723317a04 to your computer and use it in GitHub Desktop.

Select an option

Save jldavid/b6d75a2b6d0723317a04 to your computer and use it in GitHub Desktop.
Facebook Login with ACAccountType
- (void)facebookLoginWithCompletion:(void (^)(NSString *userID, NSString *email, NSString *fullName))completion
{
self.accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
NSDictionary *options = @{
ACFacebookAppIdKey:FACEBOOKAPPID,
ACFacebookPermissionsKey: @[@"read_stream", @"basic_info"],
ACFacebookAudienceKey:ACFacebookAudienceFriends
};
[self.accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error) {
if (granted)
{
//NSLog(@"Permission Granted");
NSArray *accounts = [self.accountStore accountsWithAccountType:accountType];
ACAccount *account = (ACAccount *)[accounts lastObject];
NSString *userID = [[[account valueForKey:@"properties"] valueForKey:@"uid"] stringValue];
NSString *email = [[account valueForKey:@"properties"] valueForKey:@"ACUIDisplayUsername"];
NSString *fullName = [[account valueForKey:@"properties"] valueForKey:@"ACPropertyFullName"];
completion(userID, email, fullName);
}
else
{
NSLog(@"Permission denied");
NSLog(@"%@", error);
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment