日常bug小记

  • 获取手机剩余可用容量不准
    原因:从iOS11.0开始,ytes->KB->MB->G的进制为1000.0,而不是1024.0
    代码:
    let fileUrl = URL(fileURLWithPath: NSTemporaryDirectory())
    let results = try? fileUrl.resourceValues(forKeys:  [URLResourceKey.volumeAvailableCapacityForImportantUsageKey])
         if let availableSize = results?.volumeAvailableCapacityForImportantUsage {
             // ytes->KB->MB->G
             let _availableSize = Double(availableSize) / 1000.0 / 1000.0 / 1000.0
             self.label.text = "已占用\(byte.fileSizeToString()),剩余\(String(format: "%.1f", _availableSize))G可用"
         } 
    

你可能感兴趣的:(日常bug小记)