In my app I want to download a big data file (maybe more than 50MB), but at the same time if the user has utilized lots of space in music and other things then how would the code get to know that the memory for the application is limited (for example 40 MB) and the code should now restrict the download.
Asked
Active
Viewed 2,070 times
1
-
1application consume iphone memory so you check the device memory befor you download the file :) – Rushabh Mar 05 '13 at 11:03
-
Google is your friend. Use it. – occulus Mar 05 '13 at 11:07
2 Answers
3
You can create a function to do so:
#include <sys/param.h>
#include <sys/mount.h>
+(float) diskSpaceLeft {
NSArray* thePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
const char *path = [[NSFileManager defaultManager] fileSystemRepresentationWithPath:[thePath lastObject]];
statfs(path, &tStats);
float availableSpace = (float)(tStats.f_bavail * tStats.f_bsize);
return availableSpace;
}
![](../../users/profiles/1586880.webp)
dsgriffin
- 61,907
- 17
- 128
- 134
0
use this:
#include <sys/param.h>
#include <sys/mount.h>
+(float) diskSpaceAvailable {
NSArray* pathDocDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[pathDocDir lastObject] cString], &tStats);
float total_space = (float)(tStats.f_blocks * tStats.f_bsize);
return total_space;
}
![](../../users/profiles/336905.webp)
Jonathan Day
- 18,268
- 7
- 78
- 135
![](../../users/profiles/2131765.webp)
Saurabh Singh
- 249
- 1
- 6