how to check free disk space on IOS , please help me .

I need to download AssetBundle to my game, so I first need to check how many disk space left on device .
I just tryed call Caching.spaceFree , but it returns 9223372036854775807 , its very wrong .

So I tryed to do this by myself . On Android , I implement this by calling AndroidJavaScript.

But I can’t find solution on IOS :face_with_spiral_eyes::face_with_spiral_eyes:, can anyway help me with this ? thx

http://stackoverflow.com/questions/5712527/how-to-detect-total-available-free-disk-space-on-the-iphone-ipad-device

I think I need use NSFileManager to do this, but it is a IOS api, how can I access it in Unity?

native plugin could do it real quick.

See http://forum.unity3d.com/threads/189304-Anyone-interested-in-accessing-the-entire-iOS-SDK-API-from-Unity

Lxl2013,

Did you find a way to make it work? I am also looking for the same thing …
Graham, I saw your link, but unfortunately I am not experienced enough to understand how to use the API with NSFileManager.

I have imported the free version of U3DXT and it seems to be enough to be able to access U3DXT.iOS.Native.Foundation;
But from there, I have no clue how to convert this : ios - How to detect total available/free disk space on the iPhone/iPad device? - Stack Overflow into something that works in c#.

Any help would be appreciated :slight_smile:

Thanks.

I don’t bump most of the time :slight_smile: But this is really annoying me :stuck_out_tongue:
Anyone knows how to convert the script below to make it work in c# ?
I am using the API from U3DXT.

-(uint64_t)getFreeDiskspace {
    uint64_t totalSpace = 0;
    uint64_t totalFreeSpace = 0;
    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 = %@", [error domain], [error code]);  
    }  

    return totalFreeSpace;
}

Thanks,
Laurel.

Complete Solution

https://github.com/dkrprasetya/simple-disk-utils

It is a free and good one for iOS, Android & Windows.

2 Likes

Has anyone made this work in IOS? on Android i have no issues but on IOS i get an undefined symbol error when building on Xcode (Undefined symbol: __iDiskSpace_FreeSpace) as well as during gameplay in the editor (DllNotFoundException: diskUtils)

We had this running on Unity 2020.3 on M1 macbooks but as soon as we upgraded to Unity 2021.3 it stopped working with that same DllNotFoundException

@RandomUnityDev123 did you find a solution? how did you make it work on m1?