【问题标题】:React Native url deep linking like YouTubeReact Native url 深度链接,如 YouTube
【发布时间】:2021-11-18 14:41:34
【问题描述】:

我的目标是允许用户将应用程序中的内容分享到外部世界(例如 Viber、Whats App 等)

代码如下:

import {Share} from 'react-native'

Share.share({ message:  'appscheme://feeds/:feedId'})

但是这个链接不是可点击的因此是无用的,因为无法打开应用程序

Share.share({ message: 'https://appscheme.com/feeds/:feedId'})

我的目标是实现与 YouTube 视频共享相同的行为。您可以按视频分享,将其发送给聊天中的任何人,然后从那里直接访问。 例如:

比你提前!

【问题讨论】:

  • 您希望他们获得指向您的网站/应用的link 吗?
  • 我希望能够分享一个可点击的链接,该链接重定向到 react native 应用程序
  • 你能分享你的链接配置吗?您需要在链接中添加前缀,以便设备能够在检测到其中一个前缀时重定向到您的应用。

标签: react-native deep-linking


【解决方案1】:

那叫universal link(iOS)/App Links (Android)

财政年度:https://reactnative.dev/docs/linking#open-links-and-deep-links-universal-links

获取打开您的应用的链接:

function handleURL(url) {
    // your stuff
}

useEffect(() => {
    function addLinkingEventListener() {
        Linking.addEventListener('url', evt => {
            handleURL(evt?.url)
        })
    }

    Linking.getInitialURL()
        .then(initUrl => {
            handleURL
        })
        .catch(handleError)
        .finally(() => {
            addLinkingEventListener()
        })

    return () => {
        Linking.removeEventListener('url', handleUrlEvent)
    }
}, [])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多