iPhone如何释放空间

3

我正在使用这种方法来获取设备的剩余空间(在网上找到的):

-(float)getFreeSpace{  
float freeSpace = 0.0f;  
NSError *error = nil;  
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:kSongsFolder error: &error];  

if (dictionary) {  
    NSNumber *fileSystemFreeSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize];  
    NSLog(@"%d",fileSystemFreeSizeInBytes);
    freeSpace = [fileSystemFreeSizeInBytes floatValue];  
} else { 
    //Handle error
}  
return freeSpace/1024; 

现在我从这个方法中得到了8687616.0,但当我在设备属性中检查时,我有8.1 GB的可用空间。

我该如何以MB为单位获取可用空间?这个方法好吗?因为它们之间存在差异。

2个回答

4
fileSystemFreeSizeInBytes/(1024 * 1024) gives you size in MB

0

文件大小以KB为单位,您需要再次除以1024。如果您需要以GB为单位,则需要再次除以1024。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接