새로운 정확한 API로 업데이트하여 iOS11에서 사용 가능한 디스크의 크기를 확보하십시오. 새로운 API 리소스 키에 대한 설명은 다음과 같습니다.
#if os(OSX) || os(iOS)
/// Total available capacity in bytes for "Important" resources, including space expected to be cleared by purging non-essential and cached resources. "Important" means something that the user or application clearly expects to be present on the local system, but is ultimately replaceable. This would include items that the user has explicitly requested via the UI, and resources that an application requires in order to provide functionality.
/// Examples: A video that the user has explicitly requested to watch but has not yet finished watching or an audio file that the user has requested to download.
/// This value should not be used in determining if there is room for an irreplaceable resource. In the case of irreplaceable resources, always attempt to save the resource regardless of available capacity and handle failure as gracefully as possible.
@available(OSX 10.13, iOS 11.0, *) @available(tvOS, unavailable) @available(watchOS, unavailable)
public var volumeAvailableCapacityFor Usage: Int64? { return _get(.volumeAvailableCapacityForImportantUsageKey) }
#endif
나는 키 "의 결과와 비교 교차 FileAttributeKey.systemFreeSize "키 " URLResourceKey.volumeAvailableCapacityForImportantUsageKey을 "과 "형태로 결과가 반환 발견 volumeAvailableCapacityForImportantUsageKey는 "정확히 UI에 표시된 사용 가능한 저장 일치합니다.
신속한 구현은 다음과 같습니다.
class var freeDiskSpaceInBytesImportant:Int64 {
get {
do {
return try URL(fileURLWithPath: NSHomeDirectory() as String).resourceValues(forKeys: [URLResourceKey.volumeAvailableCapacityForImportantUsageKey]).volumeAvailableCapacityForImportantUsage!
} catch {
return 0
}
}
}