๐Ÿ“– Expo - Link

Jake_Youngยท2021๋…„ 8์›” 31์ผ
2

React-Native, Expo

๋ชฉ๋ก ๋ณด๊ธฐ
1/1
post-thumbnail

โœ… ๋งํฌ์˜ ์ข…๋ฅ˜

  1. mailto: support@expo.dev
  2. tel:+123456789
  3. sms:+123456789
  4. https://expo.dev
  • ์šฐ๋ฆฐ ๋‹ค์–‘ํ•œ ๋งํฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • mailto๋Š” ์—ฌ๋Ÿฌ๋ถ„์˜ OS๊ฐ€ ์ฃผ์–ด์ง„ e-mail ์ฃผ์†Œ๋กœ ๋ฉ”์ผ์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œ์ผœ์ค€๋‹ค.
  • ์ด๊ฒƒ๋“ค์€ built-in URL์ด๊ณ , ์—ฌ๋Ÿฌ๋ถ„์ด ์ง์ ‘ custom schema๋ฅผ ๋งŒ๋“ค ์ˆ˜๋„ ์žˆ๋‹ค.
  • ์ด๋ฅผ ์šฐ๋ฆฌ๋Š” deep linking(for Android, universal links for iOS) ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
  • ์˜ˆ) slack://secret/magic-login/other-secret

๐Ÿ˜Ž ๋‚ด ์•ฑ์—์„œ ๋‹ค๋ฅธ ์•ฑ ์—ด๊ธฐ

import { Anchor } from 'expo-linking';
<Anchor href="https://google.com">Go to Google</Anchor>
<Anchor href="mailto:support@expo.dev">Email support</Anchor>

โญ๏ธ WebBrowser VS Linking

  • WebBrowser๋Š” ์•ฑ ๋‚ด ๋ชจ๋‹ฌ์— link๋ฅผ ๋„์šด๋‹ค.
  • Linking์€ ๋ณ„๋„์˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ link๋ฅผ ์—ฐ๋‹ค.
import React, { Component } from 'react';
import { Button, Linking, View, StyleSheet } from 'react-native';
import * as WebBrowser from 'expo-web-browser';
import Constants from 'expo-constants';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Button
          title="Open URL with ReactNative.Linking"
          onPress={this._handleOpenWithLinking}
          style={styles.button}
        />
        <Button
          title="Open URL with Expo.WebBrowser"
          onPress={this._handleOpenWithWebBrowser}
          style={styles.button}
        />
      </View>
    );
  }

  _handleOpenWithLinking = () => {
    Linking.openURL('https://expo.dev');
  };

  _handleOpenWithWebBrowser = () => {
    WebBrowser.openBrowserAsync('https://expo.dev');
  };
}

๐Ÿ”‘ ์•ฑ์ด ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์„ ๋•Œ, App Store๋กœ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฒ•

๐Ÿ˜ ๋‹น์‹ ์˜ ์•ฑ์„ ์ผœ๋Š” ๋ฒ•

  • ์šฐ์„  exp://๋ฅผ ์ด์šฉํ•˜๋ฉด expo ์•ฑ์„ ์ผค ์ˆ˜ ์žˆ๋‹ค.
  • ๊ทธ๋ฆฌ๊ณ  app.json์— expo > schema > (์•ฑ์ด๋ฆ„)์„ ์„ค์ •ํ•˜๋ฉด (์•ฑ์ด๋ฆ„)://๋กœ ๋‹น์‹ ์˜ ์•ฑ์„ ์ผค ์ˆ˜ ์žˆ๋‹ค.
  • ๋งŒ์•ฝ ์ด์ „์— ejected๋ฅผ ํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด, app.json ์ˆ˜์ •๋งŒ์œผ๋ก  (์•ฑ์ด๋ฆ„) ์„ค์ •์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์—†๋‹ค.
    • Under the first occurrence of CFBundleURLSchemes in ios/<your-project-name>/Info.plist
    • In the data android:scheme tag in android/app/src/main/AndroidManifest.xml

๐Ÿ“š Linking module

  • ๋งํฌ ๋งŒ๋“ค๊ธฐ ์–ด๋ ค์šฐ๋‹ˆ๊นŒ Linking.createURL() ๋ฉ”์†Œ๋“œ๋ฅผ ์ œ๊ณตํ•จ.

โœˆ๏ธ ๋‹น์‹  ์•ฑ์œผ๋กœ ๋งํฌ ํƒœ์šฐ๊ธฐ

  1. ์•ฑ์ด ์ผœ์ ธ ์žˆ๋Š” ์ƒํƒœ๋ผ๋ฉด, Linking.addEventListener('url', callback)
  2. ์•ฑ์ด ๊บผ์ ธ ์žˆ๋Š” ์ƒํƒœ๋ผ๋ฉด, Linking.getInitialURL -- it returns a Promise
  3. ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ๊ป˜ ์ „๋‹ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, Linking.createURL('path/into/app', {queryParams: {hello: 'world' }}); ์ด๋ ‡๊ฒŒ!
  4. ๋งํฌ ๋ฐ์ดํ„ฐ๋ฅผ ๋‹ค์‹œ ์ถ”์ถœํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, Linking.parse(url)๋กœ ํ•˜๋ฉด ๋จ

๐Ÿ‘ฎ๐Ÿผ ์˜ˆ์ œ

Example: linking back to your app from WebBrowser

Example: using linking for authentication

  • A common use case for linking to your app is to redirect back to your app after opening a WebBrowser. For example, you can open a web browser session to your sign in screen and when the user has successfully signed in, you can have your website redirect back to your app by using the scheme and appending the authentication token and other data to the URL.

  • Note: if try to use Linking.openURL to open the web browser for authentication then your app may be rejected by Apple on the grounds of a bad or confusing user experience. WebBrowser.openBrowserAsync opens the browser window in a modal, which looks and feels good and is Apple approved.

  • To see a full example of using WebBrowser for authentication with Facebook, see examples/with-facebook-auth. Currently Facebook authentication requires that you deploy a small webserver to redirect back to your app (as described in the example) because Facebook does not let you redirect to custom schemes, Expo is working on a solution to make this easier for you. Try it out in Expo.

  • Another example of using WebBrowser for authentication can be found at examples/with-auth0.

๐ŸŽ Universal/deep links (W/O custom schema)

iOS

  • AASA(Apple App Site Association) configuration์ด ์ค‘์š”ํ•˜๋‹ค.
  • ๊ทธ๋ฆฌ๊ณ  ๋‚ด ์†Œ์œ ์˜ domain์ด ํ•„์š”ํ•˜๋‹ค.
  • ๊ทธ๊ณณ์— /.well-known/apple-app-site-association ์ด๋ ‡๊ฒŒ ํŒŒ์ผ์„ ์˜ฌ๋ฆฐ๋‹ค.
  • ๋‚ด๋ถ€๋Š” json ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ–๊ณ  ์žˆ๋‹ค.
  • ์ด๋Ÿฌ๋ฉด ์•ฑ์ด ๋งจ ์ฒ˜์Œ ๊น”๋ฆด ๋•Œ์™€ ์—…๋ฐ์ดํŠธ ๋  ๋•Œ๋งˆ๋‹ค ์ด๊ณณ์—์„œ link ๊ด€๋ จ ์„ค์ •์„ ์—…๋ฐ์ดํŠธ ํ•œ๋‹ค.
  • Expo์—์„œ๋Š” ์•„๋ž˜ ๋‘ ๊ฐ€์ง€ ์„ค์ •์ด ํ•„์š”ํ•˜๋‹ค.
    • Add the associatedDomains configuration to your app.json, and make sure to follow Apple's specified format. Make sure not to include the protocol (https) in your URL (this is a common mistake, and will result in your universal links not working).
    • Edit your App ID on the Apple developer portal and enable the "Associated Domains" application service. Go into the App IDs section and click on your App ID. Select Edit, check the Associated Domains checkbox and click Done. You will also need to regenerate your provisioning profile after adding the service to the App ID. This can be done by running expo build:ios --clear-provisioning-profile inside of your app directory. Next time you build your app, it will prompt you to create a new one.

Android

  • ์•ˆ๋“œ๋Š” iOS๋ณด๋‹ค ์‰ฝ๋‹ค.
  • app.json์— intentFilters๋งŒ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค. ("autoVerify": true ํฌํ•จ)
  • /.well-known/assetlinks.json ์—ฌ๊ธฐ์— ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ JSON ํŒŒ์ผ์„ ์˜ฌ๋ฆฐ๋‹ค.

โ˜ข๏ธ When to not use deep links

  • custom schema๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, ์‚ฌ์šฉ์ž ์ธก์—๋Š” ์œ„ํ—˜ํ•œ ํŒŒ์ผ์ด๋‹ˆ ์—ด ์ˆ˜ ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ๋ฌธ์ด ๋‚˜์˜จ๋‹ค.
  • ์ด๋Š” ์šฐ๋ฆฌ ์•ฑ์˜ ์‹ ๋ขฐ๋„๋ฅผ ๋‚ฎ์ถ”๋Š” ์•ˆ์ข‹์€ ์ƒํ™ฉ์ด๋‹ค.
  • ๋Œ€๋ถ€๋ถ„์˜ ๋ฉ”์‹ ์ € ์•ฑ์—์„œ custon schema๋Š” url์ฒ˜๋Ÿผ ํŠน์ˆ˜ํšจ๊ณผ๊ฐ€ ์ž…ํ˜€์ง„ text๋กœ ๋ณด์ด์ง€ ์•Š๋Š”๋‹ค.
profile
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์™€ ํŒŒ์ด์ฌ ๊ทธ๋ฆฌ๊ณ  ์ปดํ“จํ„ฐ์™€ ๋„คํŠธ์›Œํฌ

0๊ฐœ์˜ ๋Œ“๊ธ€