The SDK on iOS
iOS apps use the SDK as a Swift package, with an API written for Swift: options with defaults, durations in seconds, values to read, observe or iterate, and errors that are Swift Errors. What the SDK does, what the API key allows and how the SDK behaves offline are on the SDK page; this page is the integration. Mac apps and Apple TV apps take the same package, with the same API: macOS and tvOS, visionOS and watchOS say what is different there, and how an app for Apple Vision Pro runs this one as an iPad app.
Install
The package is squiddy-cloud/squiddy-swift, on GitHub. In Xcode, File › Add Package Dependencies…, enter https://github.com/squiddy-cloud/squiddy-swift, choose Up to Next Major Version from 0.9.0, and add the library Squiddy to the app's target. In a Package.swift:
dependencies: [
.package(url: "https://github.com/squiddy-cloud/squiddy-swift", from: "0.9.0"),
],
targets: [
.target(name: "MyApp", dependencies: [.product(name: "Squiddy", package: "squiddy-swift")]),
]
The package is the Swift layer, module Squiddy, over the SDK's code compiled as SquiddyCore.xcframework, which Xcode downloads from the version's release and checks against the checksum in Package.swift.
| Minimum | iOS 15, Swift 5.9 |
app_type sent to Squiddy | ios |
| Bundle id | the main bundle's identifier |
| Files | Library/Application Support/squiddy, excluded from iCloud and computer backups |
| Size | about 5.7 MiB for a device |
Keep the key out of the repository
The key ends up inside the app, so it is not a secret (see the API key), but like any credential it does not belong in the repository. One way: an .xcconfig file that git ignores, set as the configuration file of the target's build settings, a line of Info.plist that reads it, and the code that reads the line.
// Config/Local.xcconfig: never committed
SQUIDDY_API_KEY = sqd_…
<!-- Info.plist -->
<key>SquiddyAPIKey</key>
<string>$(SQUIDDY_API_KEY)</string>
let apiKey = Bundle.main.object(forInfoDictionaryKey: "SquiddyAPIKey") as? String ?? ""
A pipeline writes the same file from a secret variable before it builds.
Initialize
Create one instance per app and Squiddy environment, when the app starts, and keep it: there is no global instance and no automatic start. The application delegate is the place, also in a SwiftUI app (@UIApplicationDelegateAdaptor), since the push update needs it:
import Squiddy
import UIKit
final class AppDelegate: NSObject, UIApplicationDelegate {
private(set) var squiddy: Squiddy?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
do {
squiddy = try Squiddy.initialize(SquiddyOptions(
host: "https://squiddy.example.com",
apiKey: apiKey,
appId: "my-app",
appVersion: "2026.11.19", // YYYY.MM.DD: Squiddy compares it as a number
appMode: "release"))
} catch {
// SquiddyInitializationError: .invalidOptions(message:) names the option to fix
}
return true
}
}
Squiddy.initialize(_:) checks every option before it creates anything and throws a SquiddyInitializationError: .invalidOptions(message:), naming the option to fix (an empty key, a version that is not YYYY.MM.DD, a negative push refresh jitter), or .storageUnavailable(message:). It returns at once and touches no file on the calling thread: the SDK reads and writes its files on its own threads, and config stays Pending until the stored configuration is read. close() stops the updates and releases the network client.
Options
SquiddyOptions is a struct; only the first five have no default.
| Option | Default | What it does |
|---|---|---|
host, apiKey, appId, appVersion, appMode | — | Required. appVersion is YYYY.MM.DD; appMode is matched against the configuration's modes, such as debug and release |
customParams | [] | The custom parameters the configuration's rules match, sent as given |
bundleId | the main bundle's | Another identifier, sent as given |
language | the user's | A language of the app's own, sent as given; setLanguage(_:) changes it later |
entityId | the installation id | An opaque id of yours that rollouts place the client by (see rollouts) |
timeout | 10 seconds | The longest one call may take, as a TimeInterval |
pushRefreshJitter | 60 seconds | The longest random wait before the check a push update asks for; zero or more |
logger | nil | A closure (SquiddyLogLevel, String, Error?) -> Void, called from the SDK's threads: .debug lines show the HTTP headers with the key redacted, .warning lines the problems the SDK recovered from |
How often the SDK checks while the app stays in the foreground is not an option: the configuration decides it, and by default there is no periodic check. The periodic check says how, and how the calls of the installations count against the key's limit.
The configuration
config, gate and strings are observables, each read in three ways: value, the value now; observe(_:), a callback on the main thread with the value now and every change, until the returned SquiddyObservation is cancelled (it is a Combine Cancellable); and values, an AsyncStream.
if let ready = squiddy.config.value as? SquiddyState.Ready {
apply(ready.configuration) // ready.origin: .cache or .network
}
for await state in squiddy.config.values {
if let failed = state as? SquiddyState.Failed, let configuration = failed.configuration {
apply(configuration) // the last valid one; failed.error says why
}
}
let timeout = try squiddy.config.value.configuration?.serverApi?.setting(key: "timeout")?.asInt()
The states are SquiddyState.Pending, SquiddyState.Ready and SquiddyState.Failed, read with as? and is. Ready comes .cache from the device and .network once Squiddy sent or confirmed it; a check that finds the configuration unchanged emits nothing. A configuration has its version, its serverApi (base URL, mode, API version, debug flag and settings), its two notices appUpdate and infoPoint, and its strings. A setting reads as text with value, or with asInt(), asDouble() and asBoolean(), which throw a SettingTypeException naming the setting when the value is not of that type.
An observation does not end when the instance is closed: cancel it, or end the task that iterates values.
The gate
gate says which screen the app shows:
let observation = squiddy.gate.observe { gate in
switch gate {
case let maintenance as AppGate.Maintenance: showMaintenance(maintenance.title, maintenance.message)
case let update as AppGate.UpdateRequired: showUpdate(update.title, update.message)
default: showApp()
}
}
UpdateRequired comes from an app-update notice marked as required for this version, Maintenance from an info-point notice that halts the app, and when both apply maintenance wins. Titles and messages arrive already localized by Squiddy; a title or a message left blank for the language arrives empty, and the gate applies all the same. The gate holds for the configuration read from the device too, so a maintenance stays on screen offline, and it is AppGate.None while there is no configuration at all. The notices stay readable one by one, with their flags, in configuration.appUpdate (isRequired) and configuration.infoPoint (isHalting): a notice without its flag is an update the app may suggest, or an information that does not stop it.
Strings
let title = squiddy.string(key: "welcome_title", fallback: "Welcome")
A string is looked up in the language the SDK asks in, then in the configuration's default language, then fallback (string(key:) without one returns nil), and only a key the language does not have goes on to the next. From SDK 0.4.0 an empty text is a text: a translation left blank in the dashboard is returned empty, with or without fallback, so a key left blank in a language stays blank in the app. Up to 0.3.0 the SDK skipped an empty text and fell back to the default language. strings is the observable of all of them, for a screen that redraws when they change. The configuration holds every language its API block supports, so a change of language changes the strings at once, without a call.
Language
The SDK asks Squiddy in the primary language of the user's first preferred language (it for it-IT), read again on NSCurrentLocaleDidChangeNotification; changing the languages in the Settings app usually ends the app, and the next launch reads the new one. An app with its own language picker calls try squiddy.setLanguage("en"), and setLanguage(nil) goes back to the user's; a blank language throws SquiddyLanguageError.invalidLanguage(message:). When the language changes, the strings switch at once, and the SDK checks with Squiddy, in the foreground, for the texts of the notices, which Squiddy localizes for each call.
When the SDK checks
At every start, after serving the stored configuration; whenever the app comes back to the foreground; and, if the API block of the configuration has a refreshInterval, at that interval while it stays there (the periodic check). An inactive app, behind Control Center or a call's banner, is still in the foreground; an app launched in the background does not call until it comes to the foreground. squiddy.refresh() checks at once, in the background too, and the outcome arrives in config.
Errors
A failed check is a SquiddyState.Failed carrying a SquiddyError, a Swift Error with a subclass per case: the table of errors says what each one means.
if let failed = squiddy.config.value as? SquiddyState.Failed {
switch failed.error {
case is SquiddyError.TenantSuspended: tellSomeone()
case let rateLimited as SquiddyError.RateLimited: log("Squiddy calls again in \(rateLimited.retryAfter ?? 0) s")
default: break
}
}
SquiddyError.RateLimited.retryAfter is a TimeInterval?, SquiddyError.ServerError.exceptionCode an Int?, and underlyingError is the failure underneath.
Push update
Push update is a button on each configuration in the dashboard: Squiddy sends a data-only message of Firebase Cloud Messaging to the configuration's topic, which reaches iOS as a background notification (content-available), and every installation subscribed to it checks within a random wait of up to pushRefreshJitter, also in the background. The SDK does not depend on Firebase: the app subscribes to the topic the SDK gives it and passes the notifications it receives to the SDK.
What it takes:
- APNs for the app: the Push Notifications capability, the Remote notifications background mode, and an APNs authentication key (
.p8) from the Apple Developer account. A background notification needs no permission from the user. - A Firebase project with the Apple app, registered with its bundle id, and the APNs key uploaded in the project's settings, Cloud Messaging. The app's
GoogleService-Info.plistgoes into the app, with theFirebaseMessagingproduct ofhttps://github.com/firebase/firebase-ios-sdk. - The project's service account key, uploaded to Squiddy. In the Firebase console, Project settings → Service accounts → Generate new private key gives a JSON file. Whoever manages the configuration uploads it in the dashboard, on the configuration's Push update tab, where Squiddy checks it with Google before keeping it, encrypted. The credential belongs to one configuration, that is one app in one environment, so staging and production can use different Firebase projects. Keep the file out of every repository.
- The subscription and the notification, in the app delegate:
import FirebaseCore
import FirebaseMessaging
// In application(_:didFinishLaunchingWithOptions:), after initialize:
FirebaseApp.configure()
Messaging.messaging().delegate = self
application.registerForRemoteNotifications()
// Hand the APNs token to Messaging yourself: it hands out its token, and so subscribes, only once it has the APNs one.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
// MessagingDelegate: Firebase hands a token at every launch and when it changes; subscribing again is harmless.
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let squiddy, fcmToken != nil else { return }
messaging.subscribe(toTopic: squiddy.pushTopic)
}
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if squiddy?.handlePush(userInfo) == true { // Squiddy's: the SDK checks within pushRefreshJitter
completionHandler(.noData)
return
}
// the app's own notifications
completionHandler(.noData)
}
Firebase's app delegate proxy is meant to pass the APNs token on by itself, but in a SwiftUI app (an app delegate through UIApplicationDelegateAdaptor) on an iPhone it did not: Messaging never handed out its token, and the app waited for ever to subscribe. Setting apnsToken in didRegisterForRemoteNotificationsWithDeviceToken is harmless where the proxy works, and needed where it does not.
handlePush(_:) returns true for Squiddy's notification, whose data says squiddy = refresh and names its topic in squiddy_topic, and false for any other, which stays the app's. It reads the entries of userInfo whose key and value are strings, as Firebase delivers a message's data. iOS gives an app woken in the background about 30 seconds: with the default wait of up to a minute, the check may come only when the app runs again, which the check on the return to the foreground covers too. An app that wants the check made while it is awake lowers pushRefreshJitter well under that limit and calls completionHandler only once the wait and the call can be over. iOS does not wake an app the user force-quit from the app switcher.
The topic is squiddy- and 64 hexadecimal digits, computed from the API key and the appId: every installation that reads the same configuration with the same key shares it, and Squiddy notifies the topic of every active key of the environment, so installations still on an older key are reached too. A version of the app with another key has another topic: keep the topic you subscribed to and, when pushTopic differs, unsubscribe from the old one.
The random wait spreads the calls: Squiddy notifies every installation at the same moment, and they all call with one key, whose calls a minute the plan limits. A notification never hastens a retry after a failure, makes no call after Unauthenticated, and a burst of notifications costs one call.
Checking that it works. Apple delivers remote notifications to devices: test on an iPhone, since the simulator does not hand a background notification to didReceiveRemoteNotification. The dashboard reports whether Firebase accepted the message for each active key; accepted is not delivered. With a logger, an installation that receives the notification logs, at .debug, "Squiddy asked for an update: checking the configuration in …", and the call follows within the wait.