简体   繁体   中英

Why FBlogin button delegate method not calling?

Steps I was done in my project:

  1. Fb appid i was created:

  2. I have added this key in my info.plist .

  3. sdk all imported to my project.

  4. appdelegate.m file

     -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { NSString *stringURL = [ url absoluteString]; if([stringURL containsString:@"fb"]) { return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } else { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; } } 
  5. my button class is fbsdkloginbutton,delegate is successfully given to the viewcontroller .

6. 在此处输入图片说明

7.Two button delegation method also implemented

-(BOOL)loginButtonWillLogin:(FBSDKLoginButton *)loginButton
{
    return YES;
}
-(void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error

{
    if(error)
    {
        NSLog(@"==%@",error);
    }
    else
    {

        NSUserDefaults *pref=[NSUserDefaults standardUserDefaults];
        [pref setObject:_txtcity.text forKey:@"CITY"];

        [self _loadData];

    }
}
-(void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton
{
    NSLog(@"user logged out");
    [[FBSDKLoginManager new] logOut];
}

- (void)_loadData {
//    FBSDKGraphRequest *request=[[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:@{ @"fields" : @"id,name,picture.width(100).height(100),email"} tokenString:nil version:nil HTTPMethod:@"GET"];
    // For more complex open graph stories, use `FBSDKShareAPI`
    // with `FBSDKShareOpenGraphContent`
    /* make the API call */
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me"
                                  parameters:@{ @"fields" : @"id,name,picture.width(100).height(100),emailid"}
                                  HTTPMethod:@"GET"];
//      @{ @"fields" : @"id,name,picture.width(100).height(100),email"}
    //@{ @"fields" : @"id,name,picture.width(100).height(100)"}]
    //    @{@"fields":@"email,public_profile"}
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        if(result)
        {
            NSLog(@"%@",connection);
            // Handle the result
            NSLog(@"%@",result);
            NSDictionary *userData = (NSDictionary *)result;
            NSLog(@"====%@",request);
            NSString *facebookID = userData[@"id"];
            name = userData[@"name"];
            //                    NSString *location = userData[@"location"][@"name"];

            email = userData[@"email"];
            imgurl = userData[@"picture"][@"data"][@"url"];
            NSLog(@"this is email=%@facebookid==%@name==%@picture url%@",email,facebookID,name,imgurl);
            NSData *Data=[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]];
            UIImage *image=[UIImage imageWithData:Data];
            datas.imgProfilePhoto=image;
            one=@"1";
            [self multiform];
        }


    }];


}

确保在XIB中为按钮提供了FBSDKLoginButton类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM