Hi,
I develop a feature to get the iPhone's total storage. After some researching, the way I can get the total storage of iPhone is using this code.
class DiskStatus {
/// Helper method to query against a resource value key
private static func getVolumeResourceValues(for key: URLResourceKey) -> URLResourceValues? {
let fileUrl = URL(fileURLWithPath: "/")
let results = try? fileUrl.resourceValues(forKeys: [key])
return results
}
/// Volume’s total capacity in bytes.
public static var totalCapacity: Int? {
get {
let resourceValues = getVolumeResourceValues(for: .volumeTotalCapacityKey)
return resourceValues?.volumeTotalCapacity
}
}
}
When I print the totalCapacity, its value is 254807724032 bytes. If I convert it to GB using decimal system it will be 254.8GB.
When I looked into Settings, the total storage of my iPhone is 256GB.
My questions are:
Why the total storage shown in Settings different with my code result?
How to achieve so that I can show exact value in Settings?
Thank you.
1
0
349