如何在从服务器下载音频文件之前检查iPhone设备上是否有足够的空间

时间:2016-03-11 09:27:21

标签: ios objective-c iphone xcode cocoa-touch

我能够成功下载音频文件..我能够获得设备的可用空间......但我的要求是在下载文件之前我想检查iPhone上是否有足够的空间如果是,则下载,如果没有那么用户可以看到一些警告信息,例如“您的设备没有足够的内存空间。”
PLZ引导我任何身体..提前致谢。

- (uint64_t)freeDiskspace

{

     uint64_t totalSpace = 0;  
     uint64_t totalFreeSpace = 0;

     __autoreleasing 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];       
          NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];    
          totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];     
          totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];     
          NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));

      }  
      else {

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

      }   
      return totalFreeSpace;
}

1 个答案:

答案 0 :(得分:0)

如果您有12.9MB的可用空间,则不会下载12.8MB的音频文件。那是在惹麻烦。检查100MB的可用空间。然后检查iPhone是否行为不当或给用户带来100MB可用空间的麻烦,如果有,则增加数量。