flowmobile / storage_space

Flutter Plugin. Get the free, available and total storage space for the device. Utility helpers for readable sizes
https://pub.dev/packages/storage_space
Other
5 stars 13 forks source link

fix: Correct iOS Storage Space Calculation to Match Device Settings #13

Open manishpatel6314 opened 3 weeks ago

manishpatel6314 commented 3 weeks ago

This PR fixes iOS storage space reporting to match device settings (Issue #12 ).

Current behavior shows incorrect values:


// Current implementation using NSHomeDirectory()
let attributes = try FileManager.default.attributesOfFileSystem(forPath: NSHomeDirectory())
return attributes[FileAttributeKey.systemSize] as! Int64  // Returns ~104GB for 128GB device

Solution
Updated implementation to use proper URLResourceValues.

Test Results
Device: iPhone (128GB)
Before:

Total Space: 104.70 GB (112418697216 bytes)
Free Space: 36.45 GB (39138611200 bytes)

After:

Total Space: 128.00 GB (matches Settings)
Free Space: 44.32 GB (matches Settings)

Changes

✅ Using URLResourceValues for accurate storage information
✅ Proper error handling added
✅ Values now match iOS Settings

Testing Done

Tested on iPhone with 128GB storage
Verified values match Settings app
Tested error scenarios
Verified both total and free space calculations