Native apps with a WebView
This page covers native apps that host your own web app in a WebView — a Swift or Kotlin shell around a site you already have.
How it works
If your app is a native shell around your own web app, the tiun SDK runs inside the WebView the same way it runs in any browser. The native shell does not call the SDK directly — it loads your web app in a WKWebView (iOS) or WebView (Android) and lets the JS SDK handle checkout, login, and paywall events.
For entitlement checks that need to flow back to native code, expose a small JS bridge that returns a verification token from getUserVerificationToken().
import { tiun } from '@tiun/sdk';
tiun.init({
snippetId: window.TIUN_SNIPPET_ID,
language: 'en', // 'en' | 'de' | 'fr'
});
window.getTiunVerification = async () => {
const token = await tiun.getUserVerificationToken();
return JSON.stringify({ token });
};The native host then calls getTiunVerification() via its JS bridge — evaluateJavascript on Android, WKWebView.evaluateJavaScript on iOS — and forwards the token to its own backend, which verifies it server-side. See server-side subscription verification for the verification round-trip.
Injecting the snippet ID from the native host
The native shell should inject window.TIUN_SNIPPET_ID before page load (via WKUserScript on iOS, or addJavascriptInterface / evaluateJavascript on Android) so the same JS bundle works across environments without hardcoded IDs.
Lifecycle
If the native host swaps the WebView's URL (full reload), the page tears down automatically — no
destroy()needed.If the native host swaps DOM content without reload, call
tiun.destroy()before loading new content so listeners and runtime config are cleaned up.
See Lifecycle and destroy() for the full matrix.
Other native SDKs (roadmap)
First-class SDKs for Swift (iOS), Kotlin (Android), and Flutter are on the roadmap.
Last updated
Was this helpful?

