react - native:如何从react native应用打开google play商店
React-Native: How to open google play store from react native app?
我正试图找到一种方法,如何打开谷歌播放商店与我的应用程序,当用户按下一个按钮内的反应原生应用程序。有什么办法可以做到吗?
如果人们懒得阅读android的烦人的SPA开发文档:
market://details?id=<package_name>
在反应原生土地:
Linking.openURL("market://details?id=<package_name>");
的例子:
Linking.openURL("market://details?id=googoo.android.btgps");
编辑:确保导入Linking
以使用它
import { View, Text, StyleSheet, Linking } from 'react-native';
你可以使用深层链接从你的应用程序中重定向用户:https://developer.android.com/distribute/tools/promote/linking.html
和react-native的Linking
API:http://facebook.github.io/react-native/docs/linking.html
对于将来的用户,您可以从接受的答案中继续阅读文档以获取更多信息。但如果你想要一个更快的结果,这里是。
用react-native
中的Linking
作为
import { Linking } from 'react-native'
Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
如果你正在使用expo,那么下面的代码就是为你准备的。
通过expo install expo-linking
安装expo-linking
包
import * as Linking from "expo-linking";
Linking.openURL("http://play.google.com/store/apps/details?id=<package_name>")
注意: <package_name>
是你的应用程序在manifest文件中定义的包名,如果你使用expo
app.json
这对我来说很有效:去google play。在那里搜索你的应用,复制url并把它放在
下面import { Linking } from "react-native";
Linking.openURL("your app url her")
看起来这个包是一个很酷的选择。
可用于React Native和Expo
https://github.com/kimxogus/react-native-version-checkExpo链接文档提及。
有可能用户没有安装Lyft应用程序,在这种情况下,你可能想要打开app/Play Store,或者让他们知道他们需要先安装它。对于这些情况,我们建议使用react-native-app-link库。
它有麻省理工学院的许可,所以我们可以很好地使用它。
让我们看看这个库是怎么做的!
https://github.com/FiberJW/react-native-app-link/blob/master/index.jsexport const openInStore = async ({ appName, appStoreId, appStoreLocale = 'us', playStoreId }) => {
if (Platform.OS === 'ios') {
Linking.openURL(`https://apps.apple.com/${appStoreLocale}/app/${appName}/id${appStoreId}`);
} else {
Linking.openURL(
`https://play.google.com/store/apps/details?id=${playStoreId}`
);
}
};
所以我把它改成:
export const openInStore = async (config: {
appStoreConfig: {
appName: string;
appId: string;
storeLocale: string;
};
playStoreConfig: {
appId: string;
};
}) => {
if (Platform.OS === "ios") {
await Linking.openURL(
`https://apps.apple.com/${config.appStoreConfig.storeLocale}/app/${config.appStoreConfig.appName}/id${config.appStoreConfig.appId}`
);
} else if (Platform.OS === "android") {
await Linking.openURL(
`https://play.google.com/store/apps/details?id=${config.playStoreConfig.appId}`
);
}
};
用法:
try {
openInStore({
playStoreConfig: {appId: "com.stevemoretz.test"},
appStoreConfig: {
appId: "com.stevemoretz.test",
appName: "Test",
storeLocale: "us",
},
});
} catch (e) {}
应该可以工作,但还没有测试!
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- 使用Jest测试React Native应用程序
- 是否存在React Native“;WEB代码安全防护”;
- React Native Listview留有余地
- 如何在React Native中绘制图形
- 在iOS和Android上使用React native时,我还能使用本机第三方lirbraries吗
- 使用createContainer将Meteor数据获取到React Native中时出现问题
- React Native当前是否支持访问用户'的通讯簿
- React Native-What'It’在任何地方都要留下逗号
- React Native DeviceEventEmitter键盘WillShow停止工作
- 与React Native的Chart.js等效
- 如何使用webview在React Native中使用Highcharts
- 如何在React Native的MapView中设置标记
- React Native NavigatorIOS
- 如何获得React Native TextInput以在提交后保持焦点
- 使用react native检测应用程序终止
- 可以在React Native中制作一个自哈希应用程序
- React Native + React - Native -router-flux:
- React Native + React - Native -router-flux:如何仅将hideNavBar应用于
- React Native-React Packager发送旧代码