Recipes
iOS kill switch without an SDK
Turn off a broken iOS feature, or require an update, from a JSON file, with URLSession and no third-party SDK.
A kill switch is a flag your app checks before using a feature, so you can turn the feature off without an App Store review. With hotcfg it's a JSON file and about 40 lines of Swift you own, with no SDK to add, update or audit.
The config
{
"kill": { "payments": false, "image_uploads": false },
"minSupportedBuild": 280,
"updateMessage": "This version is no longer supported. Please update."
}Attach a schema, so a push can never remove a key the app reads or give it the wrong type:
{
"type": "object",
"required": ["kill", "minSupportedBuild"],
"properties": {
"kill": { "type": "object", "additionalProperties": { "type": "boolean" } },
"minSupportedBuild": { "type": "integer", "minimum": 1 },
"updateMessage": { "type": "string" }
}
}Create the bin public, so reads come from Cloudflare's edge, and publish:
hotcfg bins create ios-config --public
hotcfg push ios-config.json --bin ios-config --env productionIn the app
Copy the Swift fetch code into HotcfgConfig.swift, with the bin's URL, its own cache key, and defaults that leave everything on:
static let url = URL(string: "https://api.hotcfg.run/v1/acme/ios-config")!
static let defaults = Data(#"{"kill": {}, "minSupportedBuild": 0}"#.utf8)
private static let cacheKey = "hotcfg.ios-config"It gives up after two seconds and falls back to the last good copy, then to these defaults, so the app never waits on the network to start. Decode it:
import Foundation
struct RemoteConfig: Decodable {
var kill: [String: Bool] = [:]
var minSupportedBuild = 0
var updateMessage: String?
static func load() async -> RemoteConfig {
let data = await HotcfgConfig.load()
return (try? JSONDecoder().decode(RemoteConfig.self, from: data)) ?? RemoteConfig()
}
func isKilled(_ feature: String) -> Bool { kill[feature] == true }
var updateRequired: Bool {
let build = Int(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "") ?? 0
return build < minSupportedBuild
}
}Load it at launch and whenever the app comes back to the foreground:
import SwiftUI
@main
struct MyApp: App {
@State private var config = RemoteConfig()
@Environment(\.scenePhase) private var scenePhase
var body: some Scene {
WindowGroup {
Group {
if config.updateRequired {
Text(config.updateMessage ?? "Please update the app.")
} else {
ContentView(paymentsEnabled: !config.isKilled("payments"))
}
}
.task(id: scenePhase) {
if scenePhase == .active { config = await RemoteConfig.load() }
}
}
}
}hotcfg push ios-config.json --bin ios-config --env production # with "payments": trueEvery app sees it on its next launch or foreground. The edge copy is purged on publish. When the fix ships, flip it back, or hotcfg rollback to the version before. To target only old builds, see version targeting.
Testing the failure paths
Point the URL at ?status=503 or ?delay=5000 to check that the app still starts on its saved copy. See Testing slow and failing networks.
Last updated 10 November 2026