# Mobile API

Every export of kitr/mobile, with its signature.

Every export of `kitr/mobile`, `kitr/mobile/client`, `kitr/mobile/provider`, read from the published type definitions. The [guide](/packages/mobile) shows them in use.

## kitr/mobile

### mobile

```ts
const mobile: import("@kitr/core").PlatformFactory<MobileOptions>;
```

iOS and Android through Capacitor. The native projects live in `platforms/<name>/ios` and
`platforms/<name>/android`; the app bundle is the same client build the web platform ships.

```ts
platforms: { phone: mobile({ targets: ['ios', 'android'] }) }
kitr dev phone --target ios      # live reload on a simulator or device
kitr build phone                 # builds the web bundle and syncs it into both projects
```

### MobileOptions

```ts
interface MobileOptions {
  /** Which native projects to create and run. Default both. */
  targets: MobileTarget[];
  /** Reverse-DNS bundle id. Default `com.example.<app>`. */
  appId?: string;
  /** Name shown on the home screen. Default the package name. */
  appName?: string;
  /** Custom URL scheme for deep links (`acme://`). Recorded in kitrrc.ts; register it in the native projects yourself. */
  scheme?: string;
  /** Dev server port the device loads from with `kitr dev <name>`. Default 3100. */
  port: number;
  /** Extra Capacitor config merged last (`plugins`, `server`...). */
  capacitor?: Record<string, unknown>;
}
```

Options of the mobile platform, as written in `mobile({ ... })` in kitrrc.ts and edited by `kitr config <name>`.

### MobileTarget

```ts
type MobileTarget = 'ios' | 'android';
```

A native project the mobile platform creates and builds: `ios` (Xcode) or `android` (Android Studio).

## kitr/mobile/client

### capacitorPlatform

```ts
function capacitorPlatform(): Platform;
```

'ios' | 'android' | 'web'. Reads the global Capacitor runtime, so it is correct before any import resolves.

### isCapacitor

```ts
function isCapacitor(): boolean;
```

True inside the iOS or Android shell.

### isPluginAvailable

```ts
function isPluginAvailable(name: string): boolean;
```

True when the native shell registered the Capacitor plugin `name` (`'App'`, `'Share'`); always false on the web.

### nativeOnly

```ts
function nativeOnly<T>(fn: () => Promise<T>, fallback?: T): Promise<T | undefined>;
```

Run `fn` only inside the native shell; returns `fallback` on the web.

## kitr/mobile/provider

### preferencesDriver

```ts
function preferencesDriver(): StorageDriver;
```

`@capacitor/preferences` as a kitr storage driver: hydrated at boot, written through in the background.

### mobileProvider

```ts
const mobileProvider: import("@kitr/core").KitrProvider;
```

Runtime provider of the mobile platform. Inside the Capacitor shell it registers the
`platform` driver (App plugin: state, back button, deep links) and a `storage` driver on
Preferences, which survives the OS clearing WebView storage. In a plain browser it does nothing,
so the same bundle runs on the web.

<!-- GENERATED by scripts/api-docs.mjs from the type definitions. Do not edit. -->
