Loading of file as a percentage



  • We need to make it work. label With a percentage of 0 to 100 downloads, use this code.

    - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten  totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite;{
        dispatch_async(dispatch_get_main_queue(), ^{
        [self.progressView setProgress:totalBytesWritten/totalBytesExpectedToWrite animated:YES];
    }
    

    I tried to create, but it doesn't work - in the text. label Received (null)

    - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten  totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite;{
        dispatch_async(dispatch_get_main_queue(), ^{
     NSString *percentage = [NSString stringWithFormat:@"%@%", (int)(totalBytesWritten/totalBytesExpectedToWrite)*100];
    
        _label = [[UILabel alloc]initWithFrame:CGRectMake(91, 15, 500, 50)];
        [_label setText: percentage];
        _label.numberOfLines = 1;
        _label.backgroundColor = [UIColor blackColor];
        _label.textColor = [UIColor whiteColor];
        _label.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:_label];
    
    
        });  
    

    }

    How label With interest in loading?



  • NSString *percentage = [NSString stringWithFormat:@"%d%%", (int)(((double)totalBytesWritten/(double)totalBytesExpectedToWrite)*100)];
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2