【发布时间】:2019-07-09 22:17:04
【问题描述】:
我正在寻找一种简单的方法来打开应用程序,特别是 Facebook 和 Instagram,通过我的 React Native 应用程序按下按钮。它还应该首先检查应用程序是否安装在设备上,如果没有则打开应用商店。它需要同时在 iOS 和 Android 上运行。我是初学者,所以如果你能发布一个例子会有所帮助。
【问题讨论】:
标签: react-native
我正在寻找一种简单的方法来打开应用程序,特别是 Facebook 和 Instagram,通过我的 React Native 应用程序按下按钮。它还应该首先检查应用程序是否安装在设备上,如果没有则打开应用商店。它需要同时在 iOS 和 Android 上运行。我是初学者,所以如果你能发布一个例子会有所帮助。
【问题讨论】:
标签: react-native
您可以使用 react-native 的 Linking 模块打开其他移动应用。
import { Linking } from "react-native";
const APP_ID = //ID of app need to open in play store
const appDeepLinkURL = //Most of the mobile app provide it
Linking.openURL(appDeepLinkURL).catch(err => {
Linking.openURL(
`market://details?id=${APP_ID}`
).catch(err => Linking.openURL(
`http://play.google.com/store/apps/details?id=${APP_ID}`
).catch(err => console.error("An error occurred", err)););
});
同样,你可以为 iOS 做, 可以参考官方文档here。
【讨论】:
com.google.android.apps.maps
使用 react-native Linking 组件
import {
TouchableOpacity,
Text,
Linking,
} from 'react-native';
<TouchableOpacity onPress={() => { Linking.openURL('sms:' + {contactNumber}
+ '?body=Hi'); }}>
<Text> Open Message App </Text>
</TouchableOpacity>
【讨论】: