The Swift half, written from the Capacitor 243,123 iOS plugin guide and the @capacitor/ios 8.5.2 sources, was not compiled here: that needs Xcode 10 . DiskSpace.swift reads the URL resource values volumeAvailableCapacityForImportantUsage and volumeTotalCapacity of the app's home directory. The plugin class:
@objc(DiskSpacePlugin)
public class DiskSpacePlugin: CAPPlugin, CAPBridgedPlugin {
public let identifier = "DiskSpacePlugin"
public let jsName = "DiskSpace"
public let pluginMethods: [CAPPluginMethod] = [
CAPPluginMethod(name: "getSpace", returnType: CAPPluginReturnPromise),
CAPPluginMethod(name: "canFit", returnType: CAPPluginReturnPromise)
]
private let implementation = DiskSpace()
@objc func getSpace(_ call: CAPPluginCall) {
do {
let (free, total) = try implementation.measure()
call.resolve(["freeBytes": free, "totalBytes": total])
} catch {
call.reject(error.localizedDescription, nil, error)
}
}
// canFit reads call.getDouble("bytes") and rejects with "BAD_SIZE" the same way
}CAPBridgedPlugin replaces the Android annotations with three properties: identifier, jsName (matching registerPlugin()) and pluginMethods, whose entries name each method and its return type (promise, callback or none). Forget a method there and JavaScript gets UNIMPLEMENTED on iOS only. The @objc attributes are required, because the bridge finds methods through the Objective-C runtime. The "important usage" capacity counts space the system can free by purging caches: Apple's figure for downloads the user asked for.