react-native - React Native 如何在本机应用程序上打开社交媒体 URL
问题描述
我想在我的应用程序上添加我的社交媒体链接。但是当我用 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>
解决方案
这就是您可以打开链接的方式。
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>
推荐阅读
- r - 使用 shinny 删除 DT 包中的悬停选择
- c++ - C++ 数组转数字
- javascript - 无法解构“上下文”的属性“用户”,因为它未定义
- php - Laravel 用户被禁用的问题,仍然可以登录
- python - 具有州级美国选民数据的 Choropleth 地图 (Python)
- javascript - 根据数字前后的数字匹配句子组(Javascript)
- c# - System.Data.SqlClient.SqlException:'无效的对象名称 EmpUpdate'
- c++ - 在 C++ 中使用文件 I/O 从文件中删除特定键
- firebase - 我是否错过了火力基地应该如何工作的重点?
- sql - SQL -- 如何编写一个select语句来查找连续5天下订单的客户