可能重複:
How to detect total available/free disk space on the iPhone/iPad device?獲取用空間,可用空間上iPhone編程
我想獲得iOS應用中的iOS設備的以下詳細信息。我已經在谷歌搜索,但我沒有得到這些任何想法:
- 格式化空間
- 用空間
- 自由空間
可能重複:
How to detect total available/free disk space on the iPhone/iPad device?獲取用空間,可用空間上iPhone編程
我想獲得iOS應用中的iOS設備的以下詳細信息。我已經在谷歌搜索,但我沒有得到這些任何想法:
您可以將這些使用get uidevice-extension 你需要的是以下funcitons:
- (NSNumber *) totalDiskSpace;
- (NSNumber *) freeDiskSpace;
從的UIDevice-Hardware.h
總計&免費空間,此方法將在那裏你想發送數據的路徑上返回FREESPACE
- (uint64_t)freeDiskspace{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
}
else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %d", [error domain], [error code]);
}
return totalFreeSpace;
}
你也可以使用的NSFileManager和方法
- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error
。此方法使用statfs(在其他答案中提到)。
與Xcode無關。 – 2012-12-24 12:04:51
這可以幫助你: http://stackoverflow.com/questions/5124308/device-free-space-and-sandbox-space-used –
@ H2CO3:我在想......我們可以做到這一點的沙箱應用程序? –