# Test a link that opens your app

> Give an Agent your app's link, a web link, an in-app event's or custom product page's deep link, or an App Clip link, watch it open your app in Preview, and ask for a fix.

Source: https://air.build/docs/build/test-a-link-that-opens-your-app/

A link can open your app on one screen: a link in an email or a message, a QR code, an in-app event on the App Store, a custom product page. An Agent can open such a link on a Preview device, so you see which screen your app shows without sending the link to your phone first.

> [!NOTE]
> Preview has no field for opening a link. You ask an Agent in the project's chat. It opens a link with `simulator open-url`, and an App Clip with `simulator launch` and the link (see Lifecycle in [simulator](https://air.build/docs/cli/simulator/#lifecycle)). The `simulator` help doesn't say whether this works differently in a local Team, where the devices run on the Team's Mac.

## Kinds of links

| Link | Looks like | What it needs |
| --- | --- | --- |
| Your app's own link | `myapp://orders/42` | Your app has its own link name (Apple calls it a custom URL scheme) and handles the rest of the link. If it has none, ask your Agents to add one. Apple explains it in [Defining a custom URL scheme for your app](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app). |
| A web link | `https://example.com/orders/42` | Your app and your website are set up for each other. Apple calls this associated domains and explains what each side needs in [Supporting associated domains](https://developer.apple.com/documentation/xcode/supporting-associated-domains). On the app's side it's a capability your Agents turn on: see [Turn on iCloud, App Groups or another capability](https://air.build/docs/build/turn-on-an-app-capability/). |
| An in-app event's or a custom product page's deep link | One of the two above | The deep link you gave the event or the page. See [Promote an event in your app on the store](https://air.build/docs/app-store/promote-an-in-app-event/#what-an-event-needs) and [Make a custom product page for a link or ad](https://air.build/docs/app-store/make-a-custom-product-page/#what-a-page-has). Test it before you send the event or the page to App Review. |
| An App Clip link | `https://appclip.apple.com/id?p=com.example.app.Clip` | See [Test an App Clip link](https://air.build/docs/build/test-a-link-that-opens-your-app/#test-an-app-clip-link) below. |

## Open a link in Preview

1. Make sure Preview has your app's latest build: open Preview, or tap **Reinstall** (on iPhone, the app's icon, **Restart App**). See [Run your app in Preview](https://air.build/docs/build/preview-your-app/).

2. Note the device you're looking at. Its name is on the device menu.

3. In the project's chat, give the link, the device, and the screen it should open, for example:

   ```text
   Open myapp://orders/42 on the iPhone in Preview. It should show order 42.
   ```

4. The Agent opens the link on that device. Watch it happen in Preview.

5. The Agent reads the screen the link led to and tells you what it shows. Ask for a screenshot if you want one in the chat.

6. If it's not the right screen, say what should happen instead. When the Agent has fixed and built the app, ask it to open the link again.

Name the device in your request. Picking a device in Preview changes only what you see; an Agent opens the link on the device you name, or else on the Team's default device.

### Try it with the app closed, too

Your app can get a link while it's open, or be started by it. Ask for both:

```text
Open myapp://orders/42 on the iPhone in Preview twice: once while the app is open, and once after closing the app.
```

The Agent can close the app on the device before it opens the link.

## Test an App Clip link

An App Clip's real link opens it only once the version with the App Clip is approved and live (see [Ship an App Clip](https://air.build/docs/app-store/ship-an-app-clip/)). In Preview, an Agent can open the App Clip and hand it a link of your choosing instead:

```text
Open the App Clip on the iPhone in Preview with https://appclip.apple.com/id?p=com.example.app.Clip&item=42, and check it shows item 42.
```

- The device hands the link to the App Clip as a setting the App Clip starts with (an environment variable named `_XCAppClipURL`), not the way a real link arrives. The `simulator` help says a debug build of the App Clip has to read the link from there and treat it like a link it was opened with. If yours doesn't, ask the Agent to add that.
- The App Clip starts again for each link: if it's open, it's closed first.
- To try the links of your App Clip's QR codes, give each one with its parameters. See [Ship an App Clip](https://air.build/docs/app-store/ship-an-app-clip/#share-the-link-and-qr-code).

To open the App Clip from a link on your own iPhone before it's released, see [Try your App Clip from TestFlight before release](https://air.build/docs/app-store/test-your-app-clip-in-testflight/).

## Questions

**The web link opened in the browser, not in my app.**

Your app and your website aren't set up for each other yet. See [Supporting associated domains](https://developer.apple.com/documentation/xcode/supporting-associated-domains) and ask your Agents to check both sides. To test the screen itself meanwhile, use your app's own link.

**The app opens, but not on the right screen.**

Your app doesn't handle that link yet. Tell the Agent which screen the link should open, and ask it to change the app.

**The app closes when the link opens it.**

Have an Agent read the device's log while it opens the link again. See [Find out why your app closes or crashes in Preview](https://air.build/docs/build/find-out-why-your-app-crashes-in-preview/).

**The Agent says the App Clip opened without its link.**

That device can't hand the link to an app yet, and the App Clip opened without it. Ask the Agent to get a current device by shutting this one down and starting it again. In a cloud Team, the device comes back fresh, so everyone using it loses what was open on it.

**Can I open a link in Preview myself?**

No. Preview has no control for it. Ask an Agent.

**Does this work on an Android phone in Preview?**

The `simulator` help says Android phones answer the same commands in Android's own way, and opening a link isn't among the commands it lists as Apple-only. Name the Android phone in your request. The App Clip steps are for iPhone and iPad only.

**Will a web link open my app on my own iPhone?**

Only when your website is set up for it and the app on your iPhone has Associated Domains. An install with a free Apple ID leaves Associated Domains out; install with your Team's developer account or through TestFlight. See [Install with a free Apple ID (Mac)](https://air.build/docs/build/install-with-free-apple-id/).
