I'm trying to figure out how much free space is left on my iPhone device but even though it has enough storage(more than 40gb), it returns Volume opportunistic available capacity to zero(0) or sometimes less than 20mb. I don't know how it calculates the opportunistic available capacity, but I wish to use it because I assume that it's safe to use this than Volume important available capacity. Is it possible to return such low number even when the iPhone storage is efficient?
let freeSpace: CGFloat = {
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForOpportunisticUsageKey])
if let capacity = values.volumeAvailableCapacityForOpportunisticUsage {
return CGFloat(capacity)
} else {
return 0
}
} catch {
return 0
}
}()
I want to know why opportunistic available capacity differs so much from the important available capacity.