iOS開發 - 如何獲取設備的總容量和可用容量

清除沙盒緩存時,需要顯示設備的總容量和可用容量。先研究如下(返回爲byte單位):

+ (NSNumber *)totalDiskSpace

{

    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];

    return [fattributes objectForKey:NSFileSystemSize];

}

+ (NSNumber *)freeDiskSpace

{

    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];

    return [fattributes objectForKey:NSFileSystemFreeSize];

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章