iOS 获取全部容量

  float total = [self getTotalDiskSpace];
    NSLog(@"total:%.0f GB",total/(1000*1000*1000));

- (float)getTotalDiskSpace{

    float totalsize = 0.0;
    NSError *error = nil;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
    if (dictionary){
       NSNumber *_total = [dictionary objectForKey:NSFileSystemSize];
       totalsize = [_total unsignedLongLongValue]*1.0;
    } else{

       NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
    }
    return totalsize;
}

你可能感兴趣的:(iOS 获取全部容量)