ios 저장 용량 계산
# pragma about Storage Method
//전체 저장 용량
-(uint64_t)getTotalDisk {
uint64_t totalSpace = 0;
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];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu GB memory available.", ((totalSpace/1024ll)/1024ll)/1024ll);
} else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
}
return(((totalSpace/1024ll)/1024ll)/1024ll);
}
//저장할 수 있는 용량
-(uint64_t)getFreeDisk {
uint64_t totalFreeSpace = 0;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity %llu GB Free memory available.", (((totalFreeSpace/1024ll)/1024ll)/1024ll));
} else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
}
return (((totalFreeSpace/1024ll)/1024ll)/1024ll);
}
위의 함수 호출하는곳
//앨범 용량 체크 후 json 값으로 리턴
-(NSString *) getStorage{
NSString *totalDisk = [NSString stringWithFormat:@"%llu", (unsigned long long) [self getTotalDisk]];
NSString *freeDisk = [NSString stringWithFormat:@"%llu", (unsigned long long) [self getFreeDisk]];
NSDictionary *contentDictionary = [NSDictionary dictionaryWithObjectsAndKeys:totalDisk, @"Total_Storage", freeDisk, @"Free_Storage", nil];
NSData *data = [NSJSONSerialization dataWithJSONObject:contentDictionary options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonStr = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
return jsonStr;
}
'ios 뽀개기 > objective-c' 카테고리의 다른 글
Obejctive c 클래스 변수 & 배열을 json 변환 (0) | 2019.01.02 |
---|---|
UIView 커스터마이징 & 오디오 비디오 사진 뷰어 (0) | 2018.12.28 |
ios 오디오 + 비디오 권한 체크 함수 (0) | 2018.12.20 |
FileManager (0) | 2018.12.20 |
audiosessionQueue play - 코어오디오 재생하기 (0) | 2018.12.19 |
댓글