Updated for Swift 3
@IBAction func fblogin(_ sender: Any) { let loginManager = LoginManager() UIApplication.shared.statusBarStyle = .default // remove this line if not required loginManager.logIn([ .publicProfile,.email ], viewController: self) { loginResult in print(loginResult) //use picture.type(large) for large size profile picture let request = GraphRequest(graphPath: "me", parameters: ["fields":"email,name,gender,picture"], accessToken: AccessToken.current, httpMethod: .GET, apiVersion: FacebookCore.GraphAPIVersion.defaultVersion) request.start { (response, result) in switch result { case .success(let value): print(value.dictionaryValue) case .failed(let error): print(error) } } } }
For Objective-C
You can call this method in the UIButton click event
-(void)fblogin{ FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; if ([UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:@"fb://"]]) { login.loginBehavior = FBSDKLoginBehaviorSystemAccount; } [login logInWithReadPermissions:@[@"public_profile", @"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { NSLog(@"Unexpected login error: %@", error); NSString *alertMessage = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was a problem logging in. Please try again later."; NSString *alertTitle = error.userInfo[FBSDKErrorLocalizedTitleKey] ?: @"Oops"; [[[UIAlertView alloc] initWithTitle:alertTitle message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } else { if(result.token)
Madan gupta
source share