anup gupta anup gupta - 29 days ago 16
iOS Question

login with facebook in Xcode and iOS 9 with objective C

I am trying to create an application and using

Login
with
Facebook
but it always show
error
Auth2, Please help me on this problem.

2016-05-03 15:14:36.213 loginFB[631:124818] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2016-05-03 15:14:36.225 loginFB[631:124818] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2016-05-03 15:14:36.863 loginFB[631:124818] Warning: Attempt to present <FBSDKContainerViewController: 0x12659bf90> on <ViewController: 0x12655a140> whose view is not in the window hierarchy!

Answer

last night struggle this problem i got correct Answer for my problem

    - (IBAction)loginFBAction:(id)sender{
    UIButton *button=sender;
    if ([button isSelected]) {
        //        [fb facebookLogOut];
        [button setSelected:NO];
    }else{
        FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
        [login
         logInWithReadPermissions: @[@"public_profile",@"user_friends",@"email",@"user_birthday"]
         fromViewController:self
         handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
             if (error) {
                 NSLog(@"Process error");

             } else if (result.isCancelled) {
                 NSLog(@"Cancelled");

             } else {
                 NSLog(@"Logged in");
                 [self checkUser];
             }
         }];        [button setSelected:YES];
    }
}
- (void)checkUser{
    NSMutableDictionary* parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setValue:@"id, name, email, birthday, picture" forKey:@"fields"];

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"me"
                                  parameters:parametersDic
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        // Handle the result
        NSLog(@"result %@",result);
        NSString* nameFB = [result objectForKey:@"name"];
        NSString* emailFB = [result objectForKey:@"email"];
    }];
}

this is code but you need to make sure that you have enable the your app from FB developer page if you are not enable that your application will not work i am showing here the pic of that enter image description here

here you are seeing green light side of app name for enable this green you need to go APP review option and public you app like this enter image description here

now you will be able to lunch your application and get access for the fb login.