[iOS] How to get Storage Available
how to get storage available
-(NSNumber *)getStorageAvailable
{
NSNumber *availableGiga = [NsNumber numberWithFloat:0.0f];
NSError *error = nil;
NSArray *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error:&error];
// 소수 2자리까지 표시
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.roundingIncrement = [NSNumber numberWithFloat:0.01];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
if (dictionary) {
NSNumber *availableByte = [dictionary objectForKey:NSFileSystemFreeSize];
availableGiga = [NSNumber numberWithFloat:((([availableByte floatValue] / 1024) / 1024) / 1024)];
NSLog(@"%@G", [formatter stringFromNumber:availableGiga]);
} else {
NSLog(@"Error: %@", error.description);
}
return availableGiga;
}
-(NSNumber *)getStorageAvailable
{
NSNumber *availableGiga = [NsNumber numberWithFloat:0.0f];
NSError *error = nil;
NSArray *paths = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error:&error];
// 소수 2자리까지 표시
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.roundingIncrement = [NSNumber numberWithFloat:0.01];
formatter.numberStyle = NSNumberFormatterDecimalStyle;
if (dictionary) {
NSNumber *availableByte = [dictionary objectForKey:NSFileSystemFreeSize];
availableGiga = [NSNumber numberWithFloat:((([availableByte floatValue] / 1024) / 1024) / 1024)];
NSLog(@"%@G", [formatter stringFromNumber:availableGiga]);
} else {
NSLog(@"Error: %@", error.description);
}
return availableGiga;
}
댓글
댓글 쓰기