# Tether SDK read modes

The WarpLink SDK reads the Tether code on the iPhone and sends it to WarpLink. Tether needs SDK 1.4.0 or newer on iOS, React Native and Flutter. Older SDKs do not read the code.

The SDK sends only WarpLink codes: text that starts with `wl1_`, or `wl1t_` for a test code. It never sends other clipboard text. After WarpLink uses a code, the SDK clears it from the clipboard, if the clipboard still holds that code.

## Read modes

You pick one read mode in `configure`. The default is the paste button.

| Mode | When the SDK reads | What the person sees |
|------|--------------------|----------------------|
| Paste button (default) | When the person taps a system paste button that you place in your app | One tap. This tap shows no paste prompt |
| Automatic | During the first-launch check, and again on a later launch until a check completes | iOS may show its own paste prompt |
| On call | When your code calls `readTether` | iOS may show its own paste prompt at that moment |

Use the paste button when your first-run screen has room for a button. Use automatic for the shortest path to the link. Use on call when you want to choose the moment, for example after a welcome screen.

## Read the code in the app

Install SDK 1.4.0 or later (Swift Package Manager): `.package(url: "https://github.com/WarpLinkApp/warplink-ios-sdk", from: "1.4.0")`. Earlier versions do not read the code.

Replace `YOUR_SDK_KEY` with an SDK key for this app. Create one on the Keys page of the dashboard, on the SDK keys tab. An AI agent can call `create_key` with type `sdk`.

Set the read mode with `tetherReadMode` in `configure`. The default is `.pasteButton`. The SDK then reads the code after the person taps a system paste button.

`.automatic` reads during the first-launch check, and again on a later launch until that check completes. `.onCall` reads when your code calls `WarpLink.readTether(completion:)`.

The first-launch check is the SDK's check for a link after an install. It repeats on a later launch until it completes.

In the default mode, add `WarpLinkPasteButton` to your first-run screen. It needs iOS 16. On iOS 15, use a plain button that calls `WarpLink.readTether(completion:)`, as the snippet does. iOS may show its paste prompt then.

Route links in `onLink`. In the paste button and on call modes, `onLink` first gets an estimate, if the SDK found one. An estimate is a best guess and can be the wrong link.

When the SDK reads a valid code, the exact link reaches the read callback. It reaches `onLink` again only when `onLink` got another link first. The snippet calls `routeOnce`, so each link opens once.

In automatic mode, `onLink` fires once per check. The link is exact when the SDK read a valid code. With no code, it is an estimate, if the SDK found one. Check `evidenceClass` to tell them apart.

Put each part of the snippet in its place. `lastRouted`, `routeOnce` and `handle` go at file scope. The `WarpLink.configure` block goes in your `App`'s `init()`. The `if #available` block goes in the `body` of your first-run view. Read `WarpLink.lastTetherTestReceipt` where you show or log it, for example in a button action.

The snippet calls `router.replaceRoute` and `router.showRoute`. Replace them with the app's own navigation code, which opens the screen for a link. If the app has no screen for the link, open the home screen.

Show or log the test receipt, so you can send it to `verify_setup` as `tether_test_receipt`. It is `WarpLink.lastTetherTestReceipt`. The SDK forgets it when the app restarts.

```swift
import SwiftUI
import WarpLink

// One match can reach onLink and the read callback. Route each link once.
@MainActor var lastRouted: String?
@MainActor func routeOnce(_ link: WarpLinkDeepLink, _ route: (WarpLinkDeepLink) -> Void) {
    let key = link.linkId.isEmpty ? link.destination : link.linkId
    guard key != lastRouted else { return }
    lastRouted = key
    route(link)
}

// router stands for your app's own navigation code. Replace it.
WarpLink.configure(
    apiKey: "YOUR_SDK_KEY",
    options: WarpLinkOptions(
        tetherReadMode: .pasteButton,
        onLink: { result in   // onLink runs on the main actor.
            guard case .success(let link?) = result else { return }
            if link.evidenceClass == .exact {
                routeOnce(link) { router.replaceRoute(with: $0) }   // the exact link: switch to it
            } else {
                routeOnce(link) { router.showRoute(for: $0) }       // an estimate: a best guess
            }
        }
    )
)

// On the first-run screen. Always let the person continue without it.
func handle(_ result: Result<TetherReadResult, WarpLinkError>) {
    guard case .success(.matched(let link)) = result else { return }   // Other results: .noCode, .unusable and .test.
    Task { @MainActor in routeOnce(link) { router.replaceRoute(with: $0) } }
}

if #available(iOS 16.0, *) {
    WarpLinkPasteButton(onTether: handle)
} else {
    Button("Paste your code") { WarpLink.readTether(completion: handle) }
}

// Show or log WarpLink.lastTetherTestReceipt after the SDK read the test code.
```

Android needs no Tether code. The install referrer already carries the link, and the Tether code is for iPhone only.

Do not add a paste button or a clipboard permission on Android.

Install SDK 1.4.0 or later (npm): `npm install @warplink/react-native@^1.4.0`. Earlier versions do not read the code.

Replace `YOUR_SDK_KEY` with an SDK key for this app. Create one on the Keys page of the dashboard, on the SDK keys tab. An AI agent can call `create_key` with type `sdk`.

Set the read mode with `tetherReadMode` in `configure`. The default is `'pasteButton'`. The SDK then reads the code after the person taps a system paste button.

`'automatic'` reads during the first-launch check, and again on a later launch until that check completes. `'onCall'` reads when your code calls `WarpLink.readTether()`.

The first-launch check is the SDK's check for a link after an install. It repeats on a later launch until it completes.

In the default mode, render `WarpLinkPasteButton` on your first-run screen. It renders nothing below iOS 16. There, the snippet shows a plain button that calls `WarpLink.readTether()`. iOS may show its paste prompt then.

Route links in `onLink`. In the paste button and on call modes, `onLink` first gets an estimate, if the SDK found one. An estimate is a best guess and can be the wrong link.

When the SDK reads a valid code, the exact link reaches the read callback. It reaches `onLink` again only when `onLink` got another link first. The snippet calls `routeOnce`, so each link opens once.

In automatic mode, `onLink` fires once per check. The link is exact when the SDK read a valid code. With no code, it is an estimate, if the SDK found one. Check `evidenceClass` to tell them apart.

The snippet calls `router.replaceRoute` and `router.showRoute`. Replace them with the app's own navigation code, which opens the screen for a link. If the app has no screen for the link, open the home screen.

Show or log the test receipt, so you can send it to `verify_setup` as `tether_test_receipt`. It is `await WarpLink.lastTetherTestReceipt()`. The SDK forgets it when the app restarts.

```tsx
import { Button, Platform } from 'react-native';
import { WarpLink, WarpLinkPasteButton, type TetherReadResult, type WarpLinkDeepLink } from '@warplink/react-native';

// One match can reach onLink and the read callback. Route each link once.
let lastRouted: string | undefined;
function routeOnce(link: WarpLinkDeepLink, route: (link: WarpLinkDeepLink) => void) {
  const key = link.linkId || link.destination;
  if (key === lastRouted) return;
  lastRouted = key;
  route(link);
}

// router stands for your app's own navigation code. Replace it.
await WarpLink.configure({
  apiKey: 'YOUR_SDK_KEY',
  tetherReadMode: 'pasteButton',
  onLink: ({ deepLink }) => {
    if (!deepLink) return;
    if (deepLink.evidenceClass === 'exact') routeOnce(deepLink, router.replaceRoute); // the exact link: switch to it
    else routeOnce(deepLink, router.showRoute); // an estimate: a best guess
  },
});

// On the first-run screen. Always let the person continue without it.
// The system paste button needs iOS 16. Below that it renders nothing, so show a plain button.
const iosMajor = Platform.OS === 'ios' ? parseInt(String(Platform.Version), 10) : 0;
const handle = (r: TetherReadResult) => r.kind === 'matched' && routeOnce(r.link, router.replaceRoute);

{iosMajor >= 16 && <WarpLinkPasteButton onResult={handle} />}
{iosMajor > 0 && iosMajor < 16 && (
  <Button title="Paste your code" onPress={async () => handle(await WarpLink.readTether())} />
)}

// After the SDK read the test code, show or log the receipt:
const receipt = await WarpLink.lastTetherTestReceipt();
```

Install SDK 1.4.0 or later (pubspec.yaml): `warplink_flutter: ^1.4.0`. Earlier versions do not read the code.

Replace `YOUR_SDK_KEY` with an SDK key for this app. Create one on the Keys page of the dashboard, on the SDK keys tab. An AI agent can call `create_key` with type `sdk`.

Set the read mode with `tetherReadMode` in `configure`. The default is `TetherReadMode.pasteButton`. The SDK then reads the code after the person taps a system paste button.

`TetherReadMode.automatic` reads during the first-launch check, and again on a later launch until that check completes. `TetherReadMode.onCall` reads when your code calls `WarpLink.readTether()`.

The first-launch check is the SDK's check for a link after an install. It repeats on a later launch until it completes.

In the default mode, add `WarpLinkPasteButton` to your first-run screen. It shows nothing below iOS 16. There, the snippet shows a plain button that calls `WarpLink.readTether()`. iOS may show its paste prompt then.

Route links in `onLink`. In the paste button and on call modes, `onLink` first gets an estimate, if the SDK found one. An estimate is a best guess and can be the wrong link.

When the SDK reads a valid code, the exact link reaches the read callback. It reaches `onLink` again only when `onLink` got another link first. The snippet calls `routeOnce`, so each link opens once.

In automatic mode, `onLink` fires once per check. The link is exact when the SDK read a valid code. With no code, it is an estimate, if the SDK found one. Check `evidenceClass` to tell them apart.

The snippet calls `router.replaceRoute` and `router.showRoute`. Replace them with the app's own navigation code, which opens the screen for a link. If the app has no screen for the link, open the home screen.

Show or log the test receipt, so you can send it to `verify_setup` as `tether_test_receipt`. It is `await WarpLink.lastTetherTestReceipt()`. The SDK forgets it when the app restarts.

```dart
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:warplink_flutter/warplink_flutter.dart';

// One match can reach onLink and the read callback. Route each link once.
String? lastRouted;
void routeOnce(WarpLinkDeepLink link, void Function(WarpLinkDeepLink) route) {
  final key = link.linkId.isEmpty ? link.destination : link.linkId;
  if (key == lastRouted) return;
  lastRouted = key;
  route(link);
}

// router stands for your app's own navigation code. Replace it.
await WarpLink.configure(
  apiKey: 'YOUR_SDK_KEY',
  tetherReadMode: TetherReadMode.pasteButton,
  onLink: (event) {
    switch (event) {
      case LinkEvent(:final deepLink):
        if (deepLink.evidenceClass == EvidenceClass.exact) {
          routeOnce(deepLink, router.replaceRoute); // the exact link: switch to it
        } else {
          routeOnce(deepLink, router.showRoute); // an estimate: a best guess
        }
      case ErrorEvent():
        break;
    }
  },
);

// On the first-run screen. Always let the person continue without it.
// The system paste button needs iOS 16. Below that it takes no space, so show a plain button.
final iosMajor = Platform.isIOS
    ? int.tryParse(RegExp(r'\d+').stringMatch(Platform.operatingSystemVersion) ?? '') ?? 0
    : 0;
// continueWithoutLink is your own code: show the next screen.
void handle(TetherReadResult result) => switch (result) {
  TetherMatched(:final link) => routeOnce(link, router.replaceRoute),
  TetherNoCode() || TetherUnusable() || TetherTest() => continueWithoutLink(),
};

if (iosMajor >= 16)
  WarpLinkPasteButton(onResult: handle)
else if (iosMajor > 0)
  TextButton(
    onPressed: () async => handle(await WarpLink.readTether()),
    child: const Text('Paste your code'),
  ),

// After the SDK read the test code, show or log the receipt:
final receipt = await WarpLink.lastTetherTestReceipt();
```

## The order of onLink calls

Your app gets a link from `onLink` and from the read callback. The read mode decides what `onLink` gets first.

| Mode | First `onLink` call | Second `onLink` call |
|------|---------------------|----------------------|
| Automatic | The exact link, when the SDK read a valid code. With no code, an estimate, if the SDK found one | None |
| Paste button | The estimate from the first-launch check, if the SDK found one | The exact link, when the pasted code gives a link that differs from the estimate |
| On call | The estimate from the first-launch check, if the SDK found one | The exact link, when `readTether` gives a link that differs from the estimate |

In paste button and on call modes, the SDK reads nothing at first launch. The first-launch check can only estimate from device signals. An estimate has `matchType` probabilistic and `evidenceClass` estimated. It carries no UTM values. It can be a different link than the one the person tapped.

When the SDK reads a valid code, the exact link has `matchType` deterministic, `evidenceClass` exact and `matchGuaranteed` true. It always reaches the paste button or `readTether` callback. It reaches `onLink` too, but only when `onLink` already got a different link.

`onLink` never gets the same link twice. Two links are the same when their link ids match, or their destinations match when there is no link id. Only a Tether read can call `onLink` again. `redeemInvitation` answers only its own caller. If the first-launch check found no estimate, the exact link reaches only the read callback. React Native and Flutter deliver the second call when it follows the first in the same app session.

Route on the first call, and replace that route on the second. `router` is your own navigation code:

```swift
WarpLink.configure(
    apiKey: "YOUR_SDK_KEY",
    options: WarpLinkOptions(
        tetherReadMode: .pasteButton,
        onLink: { result in
            guard case .success(let link?) = result else { return }
            if link.evidenceClass == .exact {
                router.replaceRoute(with: link)   // the exact link: switch to it
            } else {
                router.showRoute(for: link)       // an estimate: a best guess
            }
        }
    )
)
```

If the person has already acted on the estimate, keep the screen they are on. Apply the exact link's parameters, such as UTM values, to what you record.

## What the read returns

A read returns one of four results: a match with the link's destination and parameters, no code with a reason, an unusable code, or a test receipt. A failed read, for example after a network error, is an error and not a result.

A no-code result carries one of three reasons:

| No-code reason | Meaning |
|----------------|---------|
| `paste_not_allowed` | The person declined the paste |
| `clipboard_empty` | The clipboard held no text, or text that is not a WarpLink code |
| `older_sdk` | The build has no clipboard access. The name does not mean an old SDK version |

A code that WarpLink does not accept gives an unusable result, or an error when the code expired on the device. [Results](https://warplink.app/docs/tether/results) also counts the reasons that WarpLink records: `expired`, `other_app` and `link_ended`. `in_app_browser` is in the REST list, but nothing reports it yet. Use them to see why a tap did not become a match.

## Android

Android needs no clipboard. Tether on Android reads the install referrer from Google Play, as before. `WarpLink.readTether` gives `TetherReadResult.NoClipboard` to its callback once the SDK is configured, so the same shared code can call it on every platform. A `wl1t_` code in the install referrer is a test, and its receipt is in `WarpLink.lastTetherTestReceipt`.

A valid Tether code wins over probabilistic matching, even when a newer link was tapped on the same network. Results show the match method as Tether.

## Next steps

- [Test Tether](https://warplink.app/docs/tether/testing) to confirm the read with a test code
- [Privacy and App Review](https://warplink.app/docs/tether/privacy) for the review note and label text
- [iOS SDK](https://warplink.app/docs/sdks/ios), [React Native SDK](https://warplink.app/docs/sdks/react-native), [Flutter SDK](https://warplink.app/docs/sdks/flutter)
