我正在使用这种方法来获取设备的剩余空间(在网上找到的):
-(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为单位获取可用空间?这个方法好吗?因为它们之间存在差异。