Patterns and recipes for common Swift SDK integration tasks.
Handling no-fill
Subscribe to .noFill to know when no ad was returned (geo-restriction, frequency cap, etc.). The skipCode payload tells you why.
onEvent: { event in if case .noFill(let data) = event { print("no fill:", data.skipCode) }}
Sizing ads in UIKit lists
Inside UITableView / UICollectionView cells, observe InlineAdUIView.onHeightChange and trigger a row resize when it fires. The height changes as the ad streams in and stabilizes at the final value.
let adView = InlineAdUIView(ad: ad)adView.onHeightChange = { [weak self] height in self?.updateRowHeight(height)}
Live-updating session options
A subset of session options can be live-updated without recreating the session. Updates are read on the next /preload, so changes take effect on the next user message.
Live-updateable fields: variantId, regulatory, userEmail, advertisingId, vendorId. Non-nil fields overwrite; nil fields are left unchanged. To clear a field, recreate the session.
publisherToken, userId, conversationId, enabledPlacementCodes, and character are not live-updateable. Changing them mid-session would desync the /init registration or leave accumulated message history targeted at the wrong persona. Recreate the session instead.
Live-updating consent mid-session
When the user updates their consent in your CMP, call:
The next preload picks up the new value — no session recreation needed.
Switching character
The active character cannot be live-updated — the accumulated message history belongs to the original persona, so swapping mid-session would leave messages targeted at the wrong character.To switch character, destroy the current session and create a new one:
The same applies to publisherToken, userId, conversationId, and enabledPlacementCodes — recreate the session whenever any of those change.
Loading older messages (conversation restore)
When restoring a conversation from your backend, call addMessage(_:) once per historical message in order. Preloads are debounced by 10 ms, so rapid sequential calls coalesce into a single preload for the most recent user message — you won’t fire one preload per restored message.
for historicalMessage in loadedFromBackend { session.addMessage(Message( id: historicalMessage.id, role: historicalMessage.role, content: historicalMessage.content, createdAt: historicalMessage.timestamp ))}
Pass every message, suppress ads with trackOnly
Always feed every message into the session, even when you don’t want an ad to appear (e.g. when a user is on a free trial, in a no-ads region, or you’ve decided to show ads only every Nth message). Skipping addMessage(_:) calls breaks the conversation context the server relies on for targeting. See Pacing for the full pattern.
When trackOnly: true, the preload still fires (server keeps full analytics) but no .filled event will arrive for that message and session.createAd(...) won’t resolve to an ad.
SwiftUI
The SDK ships UIKit views only. Wrap InlineAdUIView in a UIViewRepresentable to embed it in SwiftUI:
import SwiftUIimport KontextSwiftSDKstruct InlineAd: UIViewRepresentable { let ad: Ad let onHeightChange: (CGFloat) -> Void func makeUIView(context: Context) -> InlineAdUIView { let view = InlineAdUIView(ad: ad) view.onHeightChange = onHeightChange return view } func updateUIView(_ uiView: InlineAdUIView, context: Context) {}}
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Kontext Documentation","colors":{"primary":"#FF682F","light":"#FF682F","dark":"#FF682F"},"logo":{"light":"https://mintcdn.com/kontext/cSTBM3iNvsT_Fm-X/logo/light.svg?fit=max\u0026auto=format\u0026n=cSTBM3iNvsT_Fm-X\u0026q=85\u0026s=31c1ad1d9c273a4f7ae529ee4ef3bedb","dark":"https://mintcdn.com/kontext/cSTBM3iNvsT_Fm-X/logo/dark.svg?fit=max\u0026auto=format\u0026n=cSTBM3iNvsT_Fm-X\u0026q=85\u0026s=22c43eed074c01e3ffb02e7028b8ae5b"},"favicon":"https://mintcdn.com/kontext/cSTBM3iNvsT_Fm-X/favicon.svg?fit=max\u0026auto=format\u0026n=cSTBM3iNvsT_Fm-X\u0026q=85\u0026s=7fcf8285ddde4170884f9cc8f6141b71","navbar":{"links":[{"href":"mailto:support@kontext.so","label":"Support"}],"primary":{"type":"button","label":"Go to kontext.so","href":"https://kontext.so"}},"styling":{"latex":false},"navigation":{"languages":[{"language":"en","href":"overview"},{"language":"zh","href":"zh/overview"}]}},"deployment":{"deploymentMetadataValue":{"subdomain":"kontext","hasAudioNarration":false,"actualSubdomain":"kontext","customDomains":["docs.kontext.so"],"gitSource":{"type":"github","owner":"kontextso","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"entitlements":{},"buildId":"6af2488cd4107adac0a78a43","clientVersion":"0.0.4167","searchFilterCounts":[{"language":"en","tag":"SDKs","count":61},{"language":"zh","tag":"SDK","count":61},{"language":"en","tag":"Conversational Ads","count":52},{"language":"en","tag":"Video Ads","count":51},{"language":"zh","tag":"对话广告","count":51},{"language":"zh","tag":"视频广告","count":50},{"language":"en","tag":"Guides","count":30},{"language":"en","tag":"Kotlin Video SDK","count":18},{"language":"zh","tag":"Kotlin 视频 SDK","count":18},{"language":"en","tag":"Swift Video SDK","count":16},{"language":"zh","tag":"Swift 视频 SDK","count":16},{"language":"zh","tag":"实践指南","count":15},{"language":"zh","tag":"指南","count":15},{"language":"en","tag":"Concepts","count":13},{"language":"zh","tag":"核心概念","count":13},{"language":"en","tag":"Resources","count":10},{"language":"zh","tag":"资源","count":8},{"language":"en","tag":"Players","count":7},{"language":"zh","tag":"播放器","count":7},{"language":"en","tag":"JavaScript SDK","count":6}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"sdk/swift/guides","slug":"/sdk/swift/guides","pageMetadata":{"title":"Guides","description":"Patterns and recipes for common Swift SDK integration tasks.","href":"/sdk/swift/guides"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Patterns and recipes for common Swift SDK integration tasks.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`handling-no-fill`,children:`Handling no-fill`}),`\n`,_jsxs(_components.p,{children:[`Subscribe to `,_jsx(_components.code,{children:`.noFill`}),` to know when no ad was returned (geo-restriction, frequency cap, etc.). The `,_jsx(_components.code,{children:`skipCode`}),` payload tells you why.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`5`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`5`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`onEvent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: { event `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` case`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`noFill`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` data) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` event {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` print`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"no fill:\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, data.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`skipCode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`sizing-ads-in-uikit-lists`,children:`Sizing ads in UIKit lists`}),`\n`,_jsxs(_components.p,{children:[`Inside `,_jsx(_components.code,{children:`UITableView`}),` / `,_jsx(_components.code,{children:`UICollectionView`}),` cells, observe `,_jsx(_components.code,{children:`InlineAdUIView.onHeightChange`}),` and trigger a row resize when it fires. The height changes as the ad streams in and stabilizes at the final value.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`4`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` adView `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` InlineAdUIView`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`ad`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: ad)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`adView.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`onHeightChange`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { [`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`weak`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] height `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`?`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`updateRowHeight`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(height)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`live-updating-session-options`,children:`Live-updating session options`}),`\n`,_jsxs(_components.p,{children:[`A subset of session options can be live-updated without recreating the session. Updates are read on the next `,_jsx(_components.code,{children:`/preload`}),`, so changes take effect on the next user message.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`session.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`updateOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`MutablePublisherOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` variantId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"new-variant\"`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`Live-updateable fields: `,_jsx(_components.code,{children:`variantId`}),`, `,_jsx(_components.code,{children:`regulatory`}),`, `,_jsx(_components.code,{children:`userEmail`}),`, `,_jsx(_components.code,{children:`advertisingId`}),`, `,_jsx(_components.code,{children:`vendorId`}),`. Non-nil fields overwrite; nil fields are left unchanged. To clear a field, recreate the session.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`publisherToken`}),`, `,_jsx(_components.code,{children:`userId`}),`, `,_jsx(_components.code,{children:`conversationId`}),`, `,_jsx(_components.code,{children:`enabledPlacementCodes`}),`, and `,_jsx(_components.code,{children:`character`}),` are `,_jsx(_components.strong,{children:`not`}),` live-updateable. Changing them mid-session would desync the `,_jsx(_components.code,{children:`/init`}),` registration or leave accumulated message history targeted at the wrong persona. Recreate the session instead.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`live-updating-consent-mid-session`,children:`Live-updating consent mid-session`}),`\n`,_jsx(_components.p,{children:`When the user updates their consent in your CMP, call:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`session.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`updateOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`MutablePublisherOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` regulatory`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`Regulatory`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`gdpr`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`gdprConsent`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\u003cnew-TCF-string>\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`The next preload picks up the new value — no session recreation needed.`}),`\n`,_jsx(Heading,{level:`2`,id:`switching-character`,children:`Switching character`}),`\n`,_jsxs(_components.p,{children:[`The active `,_jsx(_components.code,{children:`character`}),` cannot be live-updated — the accumulated message history belongs to the original persona, so swapping mid-session would leave messages targeted at the wrong character.`]}),`\n`,_jsx(_components.p,{children:`To switch character, destroy the current session and create a new one:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`session.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`destroy`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`session `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` KontextAds.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`createSession`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`SessionOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` publisherToken`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"\u003cyour-publisher-token>\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` userId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user-1234\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` conversationId`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"conv-new\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` character`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: newCharacter`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`))`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The same applies to `,_jsx(_components.code,{children:`publisherToken`}),`, `,_jsx(_components.code,{children:`userId`}),`, `,_jsx(_components.code,{children:`conversationId`}),`, and `,_jsx(_components.code,{children:`enabledPlacementCodes`}),` — recreate the session whenever any of those change.`]}),`\n`,_jsx(Heading,{level:`2`,id:`loading-older-messages-conversation-restore`,children:`Loading older messages (conversation restore)`}),`\n`,_jsxs(_components.p,{children:[`When restoring a conversation from your backend, call `,_jsx(_components.code,{children:`addMessage(_:)`}),` once per historical message in order. Preloads are debounced by 10 ms, so rapid sequential calls coalesce into a single preload for the most recent user message — you won’t fire one preload per restored message.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` historicalMessage `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` loadedFromBackend {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` session.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`addMessage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`Message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: historicalMessage.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` role`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: historicalMessage.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`role`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: historicalMessage.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` createdAt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: historicalMessage.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`timestamp`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ))`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`2`,id:`pass-every-message-suppress-ads-with-trackonly`,children:[`Pass every message, suppress ads with `,_jsx(_components.code,{children:`trackOnly`})]}),`\n`,_jsxs(_components.p,{children:[`Always feed every message into the session, even when you don’t want an ad to appear (e.g. when a user is on a free trial, in a no-ads region, or you’ve decided to show ads only every Nth message). Skipping `,_jsx(_components.code,{children:`addMessage(_:)`}),` calls breaks the conversation context the server relies on for targeting. See `,_jsx(_components.a,{href:`/concepts/pacing`,children:`Pacing`}),` for the full pattern.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`6`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` shouldShowAd `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` userMessageCount.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`isMultiple`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`session.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`addMessage`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` Message`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: msg.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`id`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`role`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: .`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: msg.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`content`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`createdAt`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`Date`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`()),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` options`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`AddMessageOptions`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`trackOnly`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`!`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`shouldShowAd)`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`When `,_jsx(_components.code,{children:`trackOnly: true`}),`, the preload still fires (server keeps full analytics) but no `,_jsx(_components.code,{children:`.filled`}),` event will arrive for that message and `,_jsx(_components.code,{children:`session.createAd(...)`}),` won’t resolve to an ad.`]}),`\n`,_jsx(Heading,{level:`2`,id:`swiftui`,children:`SwiftUI`}),`\n`,_jsxs(_components.p,{children:[`The SDK ships UIKit views only. Wrap `,_jsx(_components.code,{children:`InlineAdUIView`}),` in a `,_jsx(_components.code,{children:`UIViewRepresentable`}),` to embed it in SwiftUI:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`15`,language:`swift`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`swift`,children:_jsxs(_components.code,{language:`swift`,numberOfLines:`15`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` SwiftUI`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` KontextSwiftSDK`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`struct`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` InlineAd`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`UIViewRepresentable `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ad: Ad`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` onHeightChange: (CGFloat) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` Void`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` func`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` makeUIView`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: Context) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`->`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` InlineAdUIView {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` let`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` view `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` InlineAdUIView`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:`ad`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: ad)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` view.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`onHeightChange`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` onHeightChange`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` view`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` func`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` updateUIView`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`_`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` uiView`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: InlineAdUIView, `}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: Context) {}`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Guides","description":"Patterns and recipes for common Swift SDK integration tasks.","href":"/sdk/swift/guides"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Handling no-fill","slug":"handling-no-fill","depth":2,"children":[]},{"title":"Sizing ads in UIKit lists","slug":"sizing-ads-in-uikit-lists","depth":2,"children":[]},{"title":"Live-updating session options","slug":"live-updating-session-options","depth":2,"children":[]},{"title":"Live-updating consent mid-session","slug":"live-updating-consent-mid-session","depth":2,"children":[]},{"title":"Switching character","slug":"switching-character","depth":2,"children":[]},{"title":"Loading older messages (conversation restore)","slug":"loading-older-messages-conversation-restore","depth":2,"children":[]},{"title":"Pass every message, suppress ads with trackOnly","slug":"pass-every-message-suppress-ads-with-trackonly","depth":2,"children":[]},{"title":"SwiftUI","slug":"swiftui","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"kontext","siteName":"Kontext Documentation","title":"Guides - Kontext Documentation","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{"en":{"href":"/sdk/swift/guides","matchLevel":0},"zh":{"href":"/zh/sdk/swift/guides","matchLevel":1}}},"lastModified":"2026-05-19T17:21:06.324Z","originalFileLocation":"sdk/swift/guides.mdx","locale":"en"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Patterns and recipes for common Swift SDK integration tasks.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Kontext Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Guides - Kontext Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Patterns and recipes for common Swift SDK integration tasks.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Kontext Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.kontext.so/sdk/swift/guides\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://kontext.mintlify.site/_mintlify/api/og/v2?division=Swift+SDK\u0026amp;title=Guides\u0026amp;description=Patterns+and+recipes+for+common+Swift+SDK+integration+tasks.\u0026amp;theme=44e9612051797cc564ea14ef\u0026amp;signature=73c71f4812683a009a51cc59ea84138c7ee9e58d274843a297e53b2f09d47715\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Guides - Kontext Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Patterns and recipes for common Swift SDK integration tasks.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://kontext.mintlify.site/_mintlify/api/og/v2?division=Swift+SDK\u0026amp;title=Guides\u0026amp;description=Patterns+and+recipes+for+common+Swift+SDK+integration+tasks.\u0026amp;theme=44e9612051797cc564ea14ef\u0026amp;signature=73c71f4812683a009a51cc59ea84138c7ee9e58d274843a297e53b2f09d47715\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/kontext/3zw6PkR8hX7T_tb1/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Kontext Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#FF682F\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.kontext.so/sdk/swift/guides\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/sdk/swift/guides.md\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"en\" href=\"https://docs.kontext.so/sdk/swift/guides\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"zh\" href=\"https://docs.kontext.so/zh/sdk/swift/guides\">\u003clink data-mint-head rel=\"alternate\" hreflang=\"x-default\" href=\"https://docs.kontext.so/sdk/swift/guides\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.kontext.so/#organization\",\"name\":\"Kontext Documentation\",\"url\":\"https://docs.kontext.so\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/kontext/cSTBM3iNvsT_Fm-X/logo/light.svg?fit=max\u0026auto=format\u0026n=cSTBM3iNvsT_Fm-X\u0026q=85\u0026s=31c1ad1d9c273a4f7ae529ee4ef3bedb\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.kontext.so#website\",\"name\":\"Kontext Documentation\",\"url\":\"https://docs.kontext.so\",\"publisher\":{\"@id\":\"https://docs.kontext.so/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.kontext.so/sdk/swift/guides#webpage\",\"url\":\"https://docs.kontext.so/sdk/swift/guides\",\"name\":\"Guides\",\"description\":\"Patterns and recipes for common Swift SDK integration tasks.\",\"dateModified\":\"2026-05-19T17:21:06.324Z\",\"isPartOf\":{\"@id\":\"https://docs.kontext.so#website\"},\"breadcrumb\":{\"@id\":\"https://docs.kontext.so/sdk/swift/guides#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.kontext.so/sdk/swift/guides#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SDKs\",\"item\":\"https://docs.kontext.so/sdk/swift\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Swift SDK\",\"item\":\"https://docs.kontext.so/sdk/swift\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Guides\",\"item\":\"https://docs.kontext.so/sdk/swift/guides\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.kontext.so/sdk/swift/guides#article\",\"headline\":\"Guides\",\"name\":\"Guides\",\"description\":\"Patterns and recipes for common Swift SDK integration tasks.\",\"url\":\"https://docs.kontext.so/sdk/swift/guides\",\"mainEntityOfPage\":{\"@id\":\"https://docs.kontext.so/sdk/swift/guides#webpage\"},\"dateModified\":\"2026-05-19T17:21:06.324Z\",\"publisher\":{\"@id\":\"https://docs.kontext.so/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.kontext.so#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Kontext Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Kontext Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/sdk/swift/guides.md","siteName":"Kontext Documentation","nav":{"global":null,"languages":[{"language":"en","tabs":[{"tab":"Conversational Ads","groups":[{"group":"Get Started","pages":[{"title":"Overview","href":"/overview"},{"title":"Advertisers","href":"/advertisers"},{"title":"Publishers","href":"/publishers"}]},{"group":"Concepts","pages":[{"title":"How it works","href":"/concepts/how-it-works"},{"title":"Session lifecycle","href":"/concepts/session"},{"title":"IDs and tokens","href":"/concepts/ids-and-tokens"},{"title":"Messages","href":"/concepts/messages"},{"title":"Displaying ads","href":"/concepts/displaying-ads"},{"title":"Ad formats","href":"/concepts/ad-formats"},{"title":"Ad engine","href":"/concepts/ad-engine"},{"title":"Ad lifecycle events","href":"/concepts/events"},{"title":"Pacing","href":"/concepts/pacing"}]},{"group":"Guides","pages":[{"title":"Testing","href":"/guides/testing"},{"title":"Debugging","href":"/guides/debugging"},{"title":"IFA \u0026 ATT","href":"/guides/ifa"},{"title":"SKAdNetwork","href":"/guides/skadnetwork"},{"title":"ads.txt \u0026 app-ads.txt","href":"/guides/ads-txt"},{"title":"TCF \u0026 CMP","href":"/guides/tcf-cmp"},{"title":"Advertiser pixel","href":"/guides/advertiser-pixel"},{"title":"Best practices","href":"/guides/best-practices"}]},{"group":"SDKs","pages":[{"group":"Swift SDK","pages":[{"title":"Swift SDK","sidebarTitle":"Overview","href":"/sdk/swift"},{"title":"Installation","href":"/sdk/swift/installation"},{"title":"Showing your first ad","href":"/sdk/swift/first-ad"},{"title":"API reference","description":"Every type and method exposed by the Swift SDK.","href":"/sdk/swift/api"},{"title":"Guides","href":"/sdk/swift/guides"},{"title":"Example app","description":"Run the bundled UIKit demo against your own publisher token.","href":"/sdk/swift/example"}]},{"group":"Kotlin SDK","pages":[{"title":"Kotlin SDK","sidebarTitle":"Overview","href":"/sdk/kotlin"},{"title":"Installation","href":"/sdk/kotlin/installation"},{"title":"Showing your first ad","href":"/sdk/kotlin/first-ad"},{"title":"API reference","href":"/sdk/kotlin/api"},{"title":"Guides","href":"/sdk/kotlin/guides"},{"title":"Example app","href":"/sdk/kotlin/example"}]},{"title":"Flutter SDK","href":"/sdk/flutter"},{"title":"React Native SDK","href":"/sdk/react-native"},{"title":"React SDK","href":"/sdk/react"},{"group":"Vue SDK","pages":[{"title":"Vue SDK","sidebarTitle":"Overview","href":"/sdk/vue"},{"title":"Installation","href":"/sdk/vue/installation"},{"title":"Showing your first ad","href":"/sdk/vue/first-ad"},{"title":"API reference","href":"/sdk/vue/api"},{"title":"Guides","href":"/sdk/vue/guides"},{"title":"Example app","href":"/sdk/vue/example"}]},{"group":"JavaScript SDK","pages":[{"title":"JavaScript SDK","sidebarTitle":"Overview","href":"/sdk/js"},{"title":"Installation","href":"/sdk/js/installation"},{"title":"Showing your first ad","href":"/sdk/js/first-ad"},{"title":"API reference","href":"/sdk/js/api"},{"title":"Guides","href":"/sdk/js/guides"},{"title":"Example app","href":"/sdk/js/example"}]}]},{"group":"Resources","pages":[{"title":"Changelog","href":"/resources/changelog"},{"title":"Demos","href":"/resources/demos"},{"title":"Compliance","href":"/resources/compliance"},{"title":"Subprocessors","href":"/resources/subprocessors"},{"title":"Support","href":"/resources/support"}]}]},{"tab":"Video Ads","pages":[{"title":"Video Ads","href":"/video/overview"}]}]},{"language":"zh","pages":[{"title":"zh","href":"/zh/sdk/swift/guides"}]}]},"basePath":"","title":"Guides - Kontext Documentation","buildId":"dpl_9RFrWkXdFTJCytfx6jAofvAaEXr6","deploymentId":"dpl_9RFrWkXdFTJCytfx6jAofvAaEXr6","dynamics":[],"chunks":[]}