我想模拟存储的不足,所以我尝试复制文件util存储已满,但我发现它永远不会达到,我发现占用的存储大于系统,这怎么会发生?代码如下:
+ (void)copeFiles
{
NSString *srcPath = [self cloudStorageCacheFolderPath];
NSLog(@"copy: src path:%@ ,size:%f", srcPath, [self sizeOfcloudStorageCacheFolder]);
int base = 300;
int i = base;
while (1) {
i++;
if (i > base + 100) {
break;
}
NSInteger freeSizeM = [self freeFileStorageSize];
if (freeSizeM > 1024) {
NSString *newFilePath = [NSString stringWithFormat:@"%@-%d", srcPath, i];
[self copyFolderContentFromSrc:srcPath toDestPath:newFilePath];
NSLog(@"copy: i:%d, freeSizeM:%li", i, (long)freeSizeM);
}else {
break;
}
}
}
+ (void)copyFolderContentFromSrc:(NSString *)srcPath toDestPath:(NSString *)dstPath
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSLog(@"copy: src:%@ dst:%@", srcPath, dstPath);
BOOL isDir;
if (![fileManager fileExistsAtPath:dstPath isDirectory:&isDir] || !isDir) {
BOOL sucess = [fileManager createDirectoryAtPath:dstPath withIntermediateDirectories:YES attributes:nil error:nil];
NSLog(@"copy: isDir:%d sucess:%d", isDir, sucess);
}
NSArray* array = [fileManager contentsOfDirectoryAtPath:srcPath error:nil];
int i = 0;
for (NSString *fileName in array) {
i++;
NSString *srcFullPath = [srcPath stringByAppendingPathComponent:fileName];
NSString *toFullPath = [dstPath stringByAppendingPathComponent:fileName];
NSError *error;
BOOL isSucess = [fileManager copyItemAtPath:srcFullPath toPath:toFullPath error:&error];
NSLog(@"copy:%d", i);
if (!isSucess) {
NSLog(@"copy:error:%@", error);
}
}
}
image1 image2图像可能是不可见的,所以我提前简单地描述了这个现象。我的iPhone总共32GB,但可用的存储空间是93GB。
是的,如果再次运行它也会增加:)
它背后的原因是它只存储引用而不是实际文件。我在我的mac系统中做了同样的事情来填充模拟器的空间我最终得到了相同的256GB系统,显示了4.3 TB的空间
1)删除存储在All App目录中的所有临时文件。
2)然后清除缓存内存。
Apple将很好地管理存储空间管理,但仍有一些谜团。