ios设备获取存储空间

来源:互联网 发布:华为手机服务软件 编辑:程序博客网 时间:2024/05/17 23:10

-(void)usedSpaceAndfreeSpace{    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];    spaceLabel.text = [NSString stringWithFormat:@"已占用%0.1fG/剩余%0.1fG",([totalSpace longLongValue] - [freeSpace longLongValue])/1024.0/1024.0/1024.0,[freeSpace longLongValue]/1024.0/1024.0/1024.0];}


原创粉丝点击