iOS Integration (Swift)

Embed the AR SDK in a native iOS app using Unity as a Library (UaaL) and drive it from SwiftUI/UIKit. A thin, type-safe facade (TreedisARSDK) exposes the same commands and events as the web bridge — see the AR SDK Overview for the shared concepts.

What you receive

The SDK is not a single file — it is the Unity AR engine compiled as an embeddable framework plus a small Swift facade. You receive one package, TreedisARSDK-iOS, containing:

Item What it is What to do with it
UnityFramework.framework The compiled AR engine + bundled AR assets (the large artifact — the actual product) Add to your app target and Embed & Sign. Create/load it and add its view to your view controller per Unity's UaaL host setup.
TreedisARSDK (Swift package) The type-safe facade you call from Swift Add as a Swift Package dependency (or drop the source into your target). It binds to symbols inside UnityFramework.

You do not need Unity installed to use the SDK — you only build against the prebuilt framework.

Versioning: the engine framework and the facade are released together. When you upgrade, replace both from the same release so the protocol stays in sync.

How it works

The facade does the same JSON marshalling the web bridge does, and forwards messages into the embedded Unity engine:

  • Commands (Swift → SDK): the facade builds the { type, data } envelope and delivers it to Unity via sendMessageToGO.
  • Events (SDK → Swift): Unity emits a { event, args } envelope that the facade decodes and dispatches to your TreedisARSDKDelegate on the main thread.

Setup

After the Unity framework is loaded, wire up the SDK and drive it from your UI:

import TreedisARSDK

let sdk = TreedisARSDK.shared
sdk.delegate = self

// Forward outbound messages into the embedded Unity engine.
sdk.start { gameObject, method, message in
    UnityFramework.getInstance()?.sendMessageToGO(
        withName: gameObject, functionName: method, message: message)
}

// Initialization sequence (set window size, environment, tour, then localize):
sdk.setWindowSize(width: Int(view.bounds.width), height: Int(view.bounds.height))
sdk.setEnvironment("Production")            // or "Stage"
sdk.setTourInfo(slug: "your-tour-slug", matterId: "your-matter-id")
sdk.startLocalization()

Receiving events

Conform to TreedisARSDKDelegate. All methods have no-op defaults, so implement only what you need:

extension MyViewController: TreedisARSDKDelegate {
    func arSDK(_ sdk: TreedisARSDK, didChangeLocalization isLocalized: Bool) {
        // Update your UI when tracking is established/lost.
    }

    func arSDK(_ sdk: TreedisARSDK, didClickARObject id: Int, type: String) {
        // Present native detail UI for the tapped object.
    }

    func arSDKNavigationComplete(_ sdk: TreedisARSDK) {
        showToast("You have reached your destination!")
    }

    // Catch-all for any event without a dedicated callback (e.g. thread placement events).
    func arSDK(_ sdk: TreedisARSDK, didReceiveEvent name: String, args: [Any]) {
        print("AR event:", name, args)
    }
}

Common commands

sdk.showARObject(id: 123, type: "TAG")
sdk.hideARObject(id: 123, type: "TAG")
sdk.startNavigation(destinationName: "Conference Room A", x: 1.0, y: 0.0, z: 4.5)
sdk.stopNavigation()
sdk.confirmTeleport()
sdk.endTeleport()
sdk.clickCoords(x: 180, y: 320)   // forward a tap for 3D raycasting

// Escape hatch for any command not wrapped in a typed method:
sdk.send("setThreadCompleted", ["threadId": 7, "isCompleted": true])

Command & event reference (Swift)

The facade covers the full protocol. The most common mappings:

Protocol type / event Swift
setEnvironment setEnvironment(_:customApiUrl:customCdnUrl:)
setTourInfo setTourInfo(slug:matterId:)
windowSize setWindowSize(width:height:)
startLocalization startLocalization()
manualRelocalize manualRelocalize()
startNavigation startNavigation(destinationName:x:y:z:)
stopNavigation stopNavigation()
teleportConfirm / teleportEnd confirmTeleport() / endTeleport()
showARObject / hideARObject showARObject(id:type:) / hideARObject(id:type:)
clickCoords clickCoords(x:y:)
stopAR stopAR()
(any other) send(_:_:)
event onLocalizationStatusChanged didChangeLocalization
event onNavigationComplete arSDKNavigationComplete
event onNavigationTeleport navigationTeleport
event onNavigationDistance navigationDistance
event onARObjectClick didClickARObject
event (loading/threads/other) didReceiveEvent (catch-all)

The AR object type strings (TAG, VS_IMAGE, VS_VIDEO, VS_OBJECT, VS_HTML, POLYGON, THREAD) are listed on the AR SDK Overview page.