Kirdok
Kirdok

Reputation: 1914

Download Data Asynchronous ios

I am getting user informations from Facebook which are picture and username.Than i show to user this informations. But the problem is; picture is coming late.So i used SVProgressHUD like Loading... I want to dismiss my SVProgressHUD after download my picture and show the user.Do i need to use Asynchronous or something like that?

Here is my code part;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

RoundedImageView *profileImageView = [[RoundedImageView alloc] initWithFrame:CGRectMake(27, 80, 70, 70)];

_userNameLabel.hidden = YES;
profileImageView.hidden = YES;
[SVProgressHUD showWithStatus:@"Loading..."];

//[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(LoadingDismiss) userInfo:nil repeats:NO];

[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *FBuser, NSError *error) {
    if (error) {
        // Handle error
    }

    else {
        NSString *username = [FBuser name];
        NSLog(@"username = %@",username);

        NSString *userBirtday = [FBuser birthday];
        NSLog(@"birthday = %@",userBirtday);

        NSString *email = [FBuser objectForKey:@"email"];
        NSLog(@"email = %@",email);

        NSString *userID = [FBuser objectForKey:@"id"];
        NSLog(@"userID = %@",userID);
        //==========================================================================ResimAlma
        NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=normal", userID];
        NSURL * imageURL = [NSURL URLWithString:userImageURL];
        NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
        UIImage *image = [UIImage imageWithData:imageData];



        //Configring the rounded imageview by setting appropriate image and offset.
        profileImageView.imageOffset = 2.5;
        profileImageView.image = image;
        profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"];

        [self.view addSubview:profileImageView];

        if (image == nil) {

            profileImageView.imageOffset = 2.5;
            profileImageView.image = [UIImage imageNamed:@"noImage.png"];
            profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"];

        }else{
            profileImageView.imageOffset = 2.5;
            profileImageView.image = image;
            profileImageView.backgroundImage = [UIImage imageNamed:@"dp_holder_large.png"];

        }

        _userNameLabel.text = username;

        _userNameLabel.hidden = NO;
        profileImageView.hidden = NO;

    }
}];

[SVProgressHUD dismiss];

}

Thank you for your interest and help. :)

Upvotes: 0

Views: 138

Answers (2)

Giordano Scalzo
Giordano Scalzo

Reputation: 6342

Put

[SVProgressHUD dismiss];

inside your completion block

Upvotes: 0

TotoroTotoro
TotoroTotoro

Reputation: 17622

Put [SVProgressHUD dismiss] in the end of your completion block. With your current code, the progress indicator will dismiss immediately after you make a request to Facebook (since that call is non-blocking).

Upvotes: 1

Related Questions