Offline Operation
Bundle product data point configuration before using BLE/LAN control offline. Sign-in, cloud binding, cloud provisioning confirmation, and firmware downloads still require network access. Name each JSON file <productKey>.json and include it in the app’s productConfig.bundle. The SDK reads Documents/productConfig/<openAPIInfo>/; add a directory for any custom cloud hostname.
import Foundation
func copyProductConfigFiles() throws {
guard let source = Bundle.main.url(forResource: "productConfig", withExtension: "bundle") else {
return
}
let fm = FileManager.default
let documents = try fm.url(for: .documentDirectory, in: .userDomainMask,
appropriateFor: nil, create: true)
let files = try fm.contentsOfDirectory(at: source, includingPropertiesForKeys: nil)
.filter { $0.pathExtension == "json" }
for host in ["api.gizwits.com", "euapi.gizwits.com", "usapi.gizwits.com"] {
let directory = documents.appendingPathComponent("productConfig").appendingPathComponent(host)
try fm.createDirectory(at: directory, withIntermediateDirectories: true)
for file in files {
let destination = directory.appendingPathComponent(file.lastPathComponent)
if !fm.fileExists(atPath: destination.path) {
try fm.copyItem(at: file, to: destination)
}
}
}
}
// Run before SDK initialization; handle errors in the app.
try copyProductConfigFiles()Fetch the configuration while online:
curl 'https://api.gizwits.com/app/datapoint?product_key=<productKey>' -o '<productKey>.json'cleanCache() clears product configuration caches. Restore the files before using the SDK offline again.