作为标题,我想知道在iOS设备中写入或读取NSData的进度,使用UIProgressView显示它,使用NSThread
写入数据并使用NSTimer
检查文件大小,但我没有成功。
我该怎么做?
- (void)load:(long)section {
//set Timer
float theInterval = 0.01f;
copyFileTimer = [NSTimer scheduledTimerWithTimeInterval:theInterval target:self selector:@selector(progressFile) userInfo:nil repeats:YES];
[NSThread detachNewThreadSelector:@selector(writeFile:) toTarget:self withObject:nil];
}
- (void) writeFile:(id)sender {
[movieData writeToFile:moviePath atomically:YES];
}
- (void)progressFile {
NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:moviePath error:nil];
NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize];
NSInteger fileSize = [fileSizeNumber integerValue];
[self updateProgress:(float)fileSize / (float)size];
currentPer.text = [NSString stringWithFormat:@"%.0f%%", (float)fileSize / (float)size * 100];
if ((float)fileSize / (float)size == 1) {
[copyFileTimer invalidate];
}
}