2

i am able to download audio files successfully.. i am able to get the device free space….but my requirement is before downloading file i want to check is there enough space on iPhone if yes then download and if not then user can see some alert message like “your device does not have enough memory space.”
plz guide me any body.. Thanks in advance.

- (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;
}
mangerlahn
  • 4,389
  • 2
  • 23
  • 48
satya
  • 241
  • 3
  • 10
  • 3
    http://stackoverflow.com/questions/5712527/how-to-detect-total-available-free-disk-space-on-the-iphone-ipad-device – Nitin Gohel Mar 11 '16 at 09:34
  • @NitinGohel Thanks for your response. i am able to fetch device space and free space also. but my doubt before downloading audio file how to check device free space is sufficient or not for audio file... if not displaying alert message. if yes download the audio file. so plz guide me – satya Mar 11 '16 at 09:39
  • ask another question on how to determine the file size of the audio file. – StefanS Mar 16 '16 at 17:50

1 Answers1

-1

You wouldn't download a 12.8MB audio file if you have 12.9MB free space. That's asking for trouble. Check for 100MB free space. Then check if an iPhone misbehaves or gives the user trouble with only 100MB free space, and increase the number if it does.

gnasher729
  • 47,695
  • 5
  • 65
  • 91