본문 바로가기

iPhone dev.

아이폰 빈 공간(사용량) 구하기

아이폰의 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 로 확인한다.