0

I want to integrate UIProgressView in NSOperationQueue, where i download a image and share it. i want show the progress of download of the image. even if i run in main thread. the progressive start working after the background thread, and the progress label direct shows 100% instead of continuous update . please find my code for your reference.

NSURLRequest *request = [NSURLRequest requestWithURL:url];

    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]  completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    [self performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber  numberWithFloat:((100.0/response.expectedContentLength)*data.length)] waitUntilDone:YES];


        NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
        NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[url lastPathComponent]];
        [data writeToURL:tempURL atomically:YES];
        [sharingItems addObject:tempURL];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self shareSheetForMedia:sharingItems];
        });
       }];

-(void) updateProgress:(NSNumber *) num {
    float percentage = [num float];
     [self.progressBar setProgress:percentage animated:YES];
    NSString *percentText = [NSString stringWithFormat:@"%ld %%", percentage];
    self.progressStatusLabel.text = percentText;
}

I am not sure what's going wrong. can anyone help?

iphonedevkumar
  • 129
  • 1
  • 8

0 Answers0