Created
March 9, 2016 01:40
-
-
Save jldavid/b6d75a2b6d0723317a04 to your computer and use it in GitHub Desktop.
Facebook Login with ACAccountType
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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