Iphone获得免费空间

时间:2012-05-07 13:20:34

标签: iphone objective-c

我正在使用此方法获取设备可用空间(在网络中找到它):

-(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 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:0)

大小以KB为单位,您必须再将其除以1024.如果您需要以GB为单位,则再次除以1024