Subscription Gating (AI Trainer)
Gate AI Trainer workout generation behind your app's subscription while everything else (onboarding, the free fitness assessment, Q&A) stays available. KinesteX never shows a paywall and never processes payments — your app owns the subscription screen and the purchase flow. The trainer only enforces the gate and tells you when the user hits it.
The flow at a glance:
1. Mount the trainer with isSubscribed in customParams (from your live entitlements state). Missing/true = subscribed; only an explicit false gates generation.
2. When a non-subscriber taps Generate workout, generation is parked and the SDK emits open_subscription_flow. Present your subscription flow on top of the trainer view — don't dismiss it; the pending generation is waiting underneath.
3. Every time your flow closes, post exactly one subscription_result back into the view — "purchased" (the parked workout generates immediately, no second tap) or "dismissed" (the request is dropped; the trainer resumes and the free assessment stays reachable). Send it from every exit path: purchase success, close button, swipe-down, back gesture, purchase failure.
The event:
1{ "type": "open_subscription_flow", "source": "generate_workout", "date": "06 07 2026 14:52:10" }This event is an instruction, not a status — present your subscription flow now. It fires for new users (after onboarding) and returning users (after the readiness check-in) alike, and can also fire when the KinesteX backend rejects a generation mid-session (see backend-managed subscriptions below).
source can also be "chat_input": on the non-subscriber preview step the chat input renders locked, and tapping it fires the same event. Handle both values with the same paywall. For the full free-user journey this gate powers (free onboarding, camera assessment, plan preview, conversion), see the Free Trial & Paid Conversion use case.
Edge cases:
| Scenario | What to do |
| App killed during the purchase flow | Pass the fresh isSubscribed: true in customParams at next mount. The pending generation is not persisted across launches — the user taps Generate again. |
| Purchase fails or is refunded mid-flow | Send "dismissed" — the user can retry from the same Generate button. |
| Duplicate messages | Idempotent — the first result wins; repeats are ignored. |
| Status unknown at launch | Omit isSubscribed (treated as subscribed). If your entitlements check later resolves to active, post { "subscription_result": "purchased" } — a pending generation resumes, otherwise future generations are simply unlocked. |
No host app listening? Standalone/link integrations can pass subscriptionReturnUrl in the launch config instead — the trainer redirects the browser there instead of posting open_subscription_flow. Your subscription page then relaunches KinesteX with the same userId and isSubscribed: true. Accepted values: https:// URLs or app deep links (e.g. clientapp://subscribe); script-executing schemes are rejected.
Backend-managed subscriptions: for server-side enforcement your backend can store the user's status with KinesteX and it becomes the source of truth, overriding the launch flag — see Session Auth & Managed Subscriptions.
Launch checklist:
isSubscribedpassed incustomParamson every mount, from your live entitlements stateopen_subscription_flow→ your subscription screen, overlaid on top of the trainer view- Every exit path of your flow sends
subscription_result="purchased"or"dismissed" - Verified end-to-end: blocked generate → overlay → sandbox purchase +
"purchased"→ workout generates without relaunch; closed overlay +"dismissed"→ trainer resumes
Posting the result: Swift webViewState.sendMessage (KinesteXAIKit ≥ 1.1.6), Kotlin KinesteXSDK.sendMessage (KinesteX-SDK-Kotlin ≥ 2.2.0), Flutter KinesteXAIFramework.sendAction, React Native and React TS ref.sendAction, HTML/JS postMessage with a plain object.
1// Posts real-time messages (e.g. subscription_result) into the trainer.
2@StateObject private var webViewState = WebViewState()
3
4kit.createTrainerChatView(
5 user: UserDetails(age: 32, height: 178, weight: 76, gender: .Male, lifestyle: .Active), // or nil
6 style: IStyle(style: "dark"),
7 isLoading: $isLoading,
8 customParams: [
9 "isSubscribed": SubscriptionManager.shared.isActive
10 ],
11 onMessageReceived: handleMessage,
12 webViewState: webViewState // KinesteXAIKit ≥ 1.1.6
13)1@State private var showPaywall = false
2
3private func handleMessage(_ message: KinestexMessage) {
4 switch message {
5 case .exit_kinestex:
6 showKinesteX = false
7 case .custom_type(let data):
8 guard let type = data["type"] as? String else { return }
9 if type == "open_subscription_flow" {
10 showPaywall = true // present your paywall over the trainer
11 }
12 default:
13 break
14 }
15}
16
17// Attach your paywall on top of the trainer view (keep the trainer mounted):
18// kit.createTrainerChatView(...)
19// .fullScreenCover(isPresented: $showPaywall) { paywall }
20private var paywall: some View {
21 PaywallView(
22 onPurchaseCompleted: {
23 webViewState.sendMessage(["subscription_result": "purchased"]) // generation resumes
24 showPaywall = false
25 },
26 onDismissed: {
27 webViewState.sendMessage(["subscription_result": "dismissed"]) // trainer resumes
28 showPaywall = false
29 }
30 )
31}