#docs #articles #Swift #SDK

TelemetryDeck Swift Client Reference

The TelemetryDeck Swift Client is a Swift Package to include in your app

Include the Swift Client in your Xcode Project

See the Swift Guide on how to set up your app to use the TelemetryDeck Swift Client.

Initialization

Init the TelemetryDeck Manager at app startup, so it knows your App ID (you can retrieve the App ID in the TelemetryDeck Viewer app, under App Settings)

let configuration = TelemetryManagerConfiguration(appID: "<YOUR-APP-ID>")
TelemetryManager.initialize(with: configuration)

For example, if you’re building a scene based app, in the init() function for your App:

import SwiftUI
import TelemetryClient

@main
struct TelemetryTestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    init() {
        // Note: Do not add this code to `WindowGroup.onAppear`, which will be called
        //       *after* your window has been initialized, and might lead to out initialization
        //       occurring too late.
        let configuration = TelemetryManagerConfiguration(appID: "<YOUR-APP-ID>")
        TelemetryManager.initialize(with: configuration)
    }
}

Sending Signals

Once you’ve included the TelemetryDeck Swift Client, send signals like so:

TelemetryManager.send("appLaunchedRegularly")

TelemetryDeck Manager will create a user identifier for your user that is specific to app installation and device. If you have a better user identifier available, you can use that instead: (the identifier will be hashed before sending it)

let email = MyConfiguration.User.Email
TelemetryManager.send("userLoggedIn", for: email)

Payload Data

You can also send additional payload data with each signal:

TelemetryManager.send("databaseUpdated", with: ["numberOfDatabaseEntries": "3831"])

TelemetryDeck Manager will automatically send a base payload with these keys:

  • platform
  • systemVersion
  • appVersion
  • buildNumber
  • isSimulator
  • isTestFlight
  • isAppStore
  • modelName
  • architecture
  • operatingSystem
  • targetEnvironment

Debug Mode

TelemetryDeck Manager will not send any signals if you are in DEBUG Mode. You can override this by setting configuration.telemetryAllowDebugBuilds = true on your TelemetryManagerConfiguration instance.