代码改变世界

ios获取存储空间

2016-01-25 14:48  narisong  阅读(276)  评论(0)    收藏  举报

    NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] ;

    NSFileManager* fileManager = [[NSFileManager alloc ]init];

    NSDictionary *fileSysAttributes = [fileManager attributesOfFileSystemForPath:path error:nil];

    NSNumber *freeSpace = [fileSysAttributes objectForKey:NSFileSystemFreeSize];

    NSNumber *totalSpace = [fileSysAttributes objectForKey:NSFileSystemSize];

   NSString  * str= [NSString stringWithFormat:@"已占用%0.1fG/剩余%0.1fG",([totalSpace longLongValue] -       [freeSpace longLongValue])/1024.0/1024.0/1024.0,[freeSpace longLongValue]/1024.0/1024.0/1024.0];

    NSLog(@"--------%@",str);