Open links outside the app
Lynx has no <a href>, window.open or location, so a link can't leave your app on its own. LynxLinking hands it to the phone: to the browser, to the mail app, to another app, or to a browser sheet that opens over your app and brings the person back when they close it.
Open a page in a browser sheet
For help pages, terms and privacy pages, or a hosted page such as a payment provider's onboarding, open it with openInApp(). The page opens over your app, and the person comes straight back to where they were:
The sheet is SFSafariViewController on iOS and a Custom Tab on Android. openInApp() resolves once the person is back:
- On iOS, when they close the sheet.
- On Android, when your app comes back to the front. Android doesn't say when a Custom Tab closes, so this is as close as it can tell, and it also happens when the person switches back to your app another way.
That makes it the place to refresh what the page may have changed, such as the payout status after a payment provider's onboarding, whose result reaches your app through your backend.
openInApp() opens http and https URLs only. Pass toolbarColor to match the sheet's toolbar to your app, and controlsColor for its buttons on iOS:
The sheet isn't for signing in: it shares no sign-ins with Safari on iOS, and can't hand a result back. For a sign-in page, use LynxWebAuthSession.
Open a link in the browser or another app
openURL() opens a URL where the phone would open it if the person tapped it anywhere else: https in the default browser, mailto: in the mail app, tel: in the phone app, and another app's own scheme in that app. A link to a site whose app is installed, such as a shop with its own app, opens the app.
It resolves once the phone has handed the URL over, and rejects with a LinkingError whose code is failed when nothing on the phone opens it, such as a mailto: link on a phone without a mail app.
Check before you link
canOpenURL() says whether something on the phone opens a URL, so you can leave out a link to an app that isn't installed:
iOS answers only for the schemes your app declares, and Android 11 and later only for the apps it says it looks for. For any other scheme, the answer is false. http, https, mailto, tel and sms are always declared. Add the others to canOpenURLSchemes in angular.json, and ng build --platform writes them into Info.plist's LSApplicationQueriesSchemes and the Android manifest's <queries>:
Give the scheme alone, without ://. iOS reads no more than 50, the five always declared included. openURL() needs none of this: it opens any scheme.
In the web preview, Lynx Explorer and tests
- In the web preview,
openURL()andopenInApp()open a new tab, andcanOpenURL()resolvestrue, since a browser can't tell.openInApp()resolves when the person closes the tab or comes back to your app's tab. Browsers block a new tab that doesn't come from a tap, so call them from a tap handler, before anything is awaited. - In Lynx Explorer, which doesn't have your app's native modules,
openURL()andopenInApp()reject withunavailable, andcanOpenURL()resolvesfalse. Try links on a simulator, emulator or phone withng serve --platform iosor--platform android. To use them in your own native app, see Embed in a Native App. - In unit tests, the testing library records each URL instead of opening it, so a spec can check where a tap leads:
Related
LynxLinkingreference- Open the app from a link: links that come the other way
- Sign in with a web page
- Run on iOS and Android
