SDKsiOS

Migrate to 1.0

Replace the legacy prefetch / resolveAd / cancelPrefetch calls, KoahAdLoader, and the override-sizing initializers with the 1.0 API.

Prompt for coding agents

I use Koah's iOS SDK (the KoahAds Swift package) on a 0.x version. Migrate my integration to the 1.0 API. Read https://docs.koahlabs.com/sdk/ios/migration and apply it to this project.

What changes

Aspect0.x1.0
PrefetchKoah.shared.prefetch(query:queryResponse:messageId:conversationId:)Koah.shared.prefetchAd(adContext:cacheKey:)
Await a resultKoah.shared.resolveAd(query:queryResponse:messageId:conversationId:) returns KoahAdStateKoah.shared.requestAd(adContext:cacheKey:) returns KoahAdResult
CancelKoah.shared.cancelPrefetch(messageId:)Koah.shared.cancelPrefetchAd(cacheKey:)
Observable loading stateKoahAdLoader with a published stateRemoved — warm with prefetchAd, render with KoahCard(cacheKey:)
Card size boundsKoahCard(adContext:overrideMaxWidth:overrideMaxHeight:cacheKey:)width: / height: of type KoahAxisSize: .fixed(_:), .range(min:max:), .fill

Migrate each call

Prefetch

Koah.shared.prefetch(
    query: question,
    queryResponse: answer,
    messageId: messageId
)

The legacy calls were conversation-only; KoahAdContext also has .article(...), .feed(...), and .static for other surfaces — see Ad context.

Resolve a result

let state = await Koah.shared.resolveAd(
    query: question,
    queryResponse: answer,
    messageId: messageId
)
if state == .filled { showAdSlot() }

Cancel a prefetch

Koah.shared.cancelPrefetch(messageId: messageId)

Replace KoahAdLoader

struct MessageRow: View {
    let msg: Message
    @StateObject private var adLoader: KoahAdLoader

    init(msg: Message) {
        self.msg = msg
        _adLoader = StateObject(wrappedValue: KoahAdLoader(
            query: msg.query, queryResponse: msg.text, messageId: msg.id
        ))
    }

    var body: some View {
        if adLoader.state == .filled {
            KoahCard(cacheKey: msg.id)
        }
    }
}

prefetchAd warms the cache (concurrent calls for the same cacheKey share one in-flight fetch) and KoahCard(cacheKey:) renders the warmed slot — nothing renders on no-fill. To drive your own reserve/collapse layout from the outcome, use requestAd instead — see Use Cases.

Replace size overrides

KoahCard(
    adContext: .conversation(question: question, answer: answer),
    overrideMaxWidth: 360,
    overrideMaxHeight: 420,
    cacheKey: messageId
)

.range(max:) reproduces the old max-only bound exactly. The full KoahAxisSize model — .fixed(_:), .range(min:max:), .fill, or nil to leave an axis unbounded — is in Card sizing.

Install 1.0

Update your Swift Package dependency to the stable 1.0 release. An up-to-next-major range starting at 0.x will not upgrade across the 1.0 boundary:

dependencies: [
  .package(url: "https://github.com/koahlabs/swift-package-manager-koah-ads", from: "1.1.0")
]

In Xcode: File → Add Package Dependencies…, then Dependency Rule → Up to Next Major Version, starting at 1.1.0.

Need help upgrading? Email support@koahlabs.com.

Was this helpful?