Simze Simze - 8 months ago 34
iOS Question

Checking disk space on cordova iOS

I am trying to check disk space available in mobile using below code:

cordova.exec(function(result) {
var diskSizeInMB = result/1024;
}, function(error) {
alert("Error: " + error);
}, "File", "getFreeDiskSpace", []);

In Android device it gives me correct result, whereas if I use iPhone/iPad it always returns me 0 as a output. Can anyone guide me how to resolve this issue? Or is there a way to check the disk size in iOS using cordova without writing custom plugin? To make this happen I haven't changed any configuration changes


It was a bug, but was fixed long time ago.

Old answer:

I confirm there is a bug on the code, the problem is getFreeDiskSpace is undocumented and cordova team want to remove the native code as getFreeDiskSpace isn't part of the w3c file API.

If you want to fix the bug for you app, go to CDVFile.m and change the line

NSNumber* pNumAvail = [self checkFreeDiskSpace:self.appDocsPath];


NSNumber* pNumAvail = [self checkFreeDiskSpace:self.rootDocsPath];

on the getFreeDiskSpace method