Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickludlam/393672 to your computer and use it in GitHub Desktop.
Save nickludlam/393672 to your computer and use it in GitHub Desktop.
// Check that you have a minimum amount of disk space free on an iPhoneOS device
- (BOOL)hasDiskSpaceAvailable {
NSUInteger minimumDiskSpace = 400 * 1024 * 1024; // 400MB limit
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[paths lastObject] cString], &tStats);
NSUInteger availableDisk = tStats.f_bavail * tStats.f_bsize;
NSLog(@"Available disk is %d", availableDisk);
if (availableDisk < minimumDiskSpace) { // availableDisk is less than 400MB
return NO;
} else {
return YES;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment