You can try this code. Based on SDK version 4.0. It is changed in 4.0 compared to the old version.
In App delegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; }
In viewController.m file
- (IBAction)btnFacebookPressed:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error } else if (result.isCancelled) { // Handle cancellations } else { if ([result.grantedPermissions containsObject:@"email"]) { NSLog(@"result is:%@",result); [self fetchUserInfo]; } } }]; } -(void)fetchUserInfo { if ([FBSDKAccessToken currentAccessToken]) { NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]); [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"resultis:%@",result); } else { NSLog(@"Error %@",error); } }]; } }
In viewdidload mode, call this function fetchUserInfo
[self fetchUserInfo]
By calling this method, you will receive an access token after logging in and you want to clearly indicate the permission to the email address. using this method you can receive an email from the user. enjoy
source share