0

Possible Duplicate:
How to detect total available/free disk space on the iPhone/iPad device?

I would like to get the following details of an iOS device in an iOS app. I have searched in Google, but I didn't get any ideas for these:

  1. Formatted Space
  2. Used Space
  3. Free Space
Community
  • 1
  • 1
SRI
  • 1,466
  • 20
  • 36

4 Answers4

1

make C system call to statfs.

see: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/statfs.2.html

and this SO answer: check enough space on iphone device before downloading files

Community
  • 1
  • 1
Daij-Djan
  • 47,307
  • 15
  • 99
  • 129
1

For total & Free spaces, this method will return freeSpace

- (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 = %d", [error domain], [error code]);  
   }  

   return totalFreeSpace;
}
Anoop Vaidya
  • 45,475
  • 15
  • 105
  • 134
0

You can get these using uidevice-extension What you need are the following funcitons:

- (NSNumber *) totalDiskSpace;
- (NSNumber *) freeDiskSpace;

from UIDevice-Hardware.h

Misha
  • 4,912
  • 5
  • 33
  • 59
0

You could also use NSFileManager and the method

- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error

on the path where you would like to send data. This method uses statfs (mentioned in other answers).

johan
  • 6,238
  • 5
  • 42
  • 66