【问题标题】:React Native how to open Social Media URL's on native appReact Native 如何在本机应用程序上打开社交媒体 URL
【发布时间】:2021-07-30 05:39:03
【问题描述】:

我想在我的应用中添加我的社交媒体链接。 但是当我用 url 添加它们时,它们会在浏览器上打开。 当我使用 facebook:// 系统时,它在 Android 上不起作用。

我希望我的 URL 像“如果应用存在,则在应用上打开它”一样工作。

这在 Android 上不起作用:

import * as Linking from 'expo-linking'

          <TouchableOpacity style={[styles.iconButton, { backgroundColor: '#3b5998' }]} onPress={() => Linking.openURL('fb://page/blablabla')}>
            <FontAwesome name="facebook" size={26} color="#fff" />
          </TouchableOpacity>

这不会在他们的原生应用上打开 URL:

          <TouchableOpacity style={[styles.iconButton, { backgroundColor: '#3b5998' }]} onPress={() => Linking.openURL('https://www.facebook.com/blablabla')}>
            <FontAwesome name="facebook" size={26} color="#fff" />
          </TouchableOpacity>

【问题讨论】:

标签: react-native expo


【解决方案1】:

这是打开链接的方法。

import { View, Text, Image, Linking, TouchableOpacity} from 'react-native'


<TouchableOpacity style={{ marginVertical: 5 }} onPress={()=>{ Linking.openURL(item.link)}}>
   <Text style={{ alignSelf: 'center', color: '#2575FC' }}>
       Click here to read more
   </Text>
</TouchableOpacity>

【讨论】:

猜你喜欢
  • 2022-11-15
  • 2022-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-07
  • 2021-07-19
  • 1970-01-01
  • 2019-08-24
相关资源
最近更新 更多