You need to create a label with file download percentages from 0 to 100 using 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]; } 

Tried to create, but this code does not work - in the text label I receive (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 to create a label with percent load?

    1 answer 1

     NSString *percentage = [NSString stringWithFormat:@"%d%%", (int)(((double)totalBytesWritten/(double)totalBytesExpectedToWrite)*100)]; 
    • Now 0% and does not go any further - user214155
    • Does totalBytesWritten change? - Max Mikheyenko
    • Yes, totalBytesWritten is changing - user214155
    • you can try to bring the percentage to the console and see if it changes - Max Mikheyenko
    • How exactly should be displayed in the console? - user214155