2

I am doing Facebook integration, first i have to authenticate and then i have to fetch details. During this process i am showing HUD loader. After authentication the Hud fades and not showing clearly.My code follows,please suggest me if i am doing anything wrong.

-(IBAction)btn_FacebookClicked:(id)sender
{

        HUD = [[MBProgressHUD alloc] initWithView:self.view];
        [self.view addSubview:HUD];
        HUD.delegate = self;
        HUD.labelText =@"Loading";
        HUD.dimBackground=YES;
        [HUD show:YES];
        [self performSelectorInBackground:@selector(FacebookLogin) withObject:nil];



}


-(void)FacebookLogin
{

        if(!accountStore)
            accountStore = [[ACAccountStore alloc] init];

        ACAccountType *facebookTypeAccount = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];

        [accountStore requestAccessToAccountsWithType:facebookTypeAccount
                                              options:@{ACFacebookAppIdKey: @"**********", ACFacebookPermissionsKey: @[@"email"]}
                                           completion:^(BOOL granted, NSError *error) {
                                               if(granted){
                                                   NSArray *accounts = [accountStore accountsWithAccountType:facebookTypeAccount];
                                                   facebookAccount = [accounts lastObject];
                                                   NSLog(@"Success");

                                                 [self userfbDetail];
                                               }else{
                                                   // ouch
                                                    [HUD hide:YES];
                                                   NSLog(@"Fail");
                                                   NSLog(@"Error: %@", error);
                                               }
                                           }];
    }


}
// Get user facebook details
- (void)userfbDetail{


    NSURL *meurl = [NSURL URLWithString:@"https://graph.facebook.com/me"];

    SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                              requestMethod:SLRequestMethodGET
                                                        URL:meurl
                                                 parameters:nil];

    merequest.account = facebookAccount;

    [merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        //  NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSMutableArray *arr_facebook=[[NSMutableArray alloc]init];
        arr_facebook=[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
        NSString *firstname=[arr_facebook valueForKey:@"name"];

        NSString *user=[NSString stringWithFormat:@"Welcome %@",firstname];
        ALERT(user);
        [HUD hide:YES];


    }];

}
user2702179
  • 187
  • 2
  • 13

0 Answers0