아이폰의 free space를 프로그램으로 구하려면 다음의 함수를 사용한다:
- (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;
}
return값을 NSLog로 찍어볼 땐 %lld 로 확인한다.
'iPhone dev.' 카테고리의 다른 글
AVAssetExportSession 을 이용한 비디오 transcoding(stackoverflow) (0) | 2013.12.11 |
---|---|
UIImage 방향 바꾸기 (0) | 2013.01.10 |
UIButton 이미지 비율 조절하기 (0) | 2012.12.01 |
아이폰 3GS/4/4S와 5 화면 구분하기 (0) | 2012.11.15 |
아이콘 이름 localization (0) | 2012.09.26 |