在我们的React Native应用程序中,我们有一个链接指导用户下载该应用程序的较新版本。问题在于,在Android版本中,这应该指向Play商店。在iOS版本中,链接应指向App Store。有什么方法可以在构建时插入适当的链接吗?这是我们使用链接的代码。
_handleDownloadPress = () => {
const url = 'https://xxxx.app.link/example';
Linking.canOpenURL(url).then(supported => {
supported && Linking.openURL(url);
}, (err) => console.log(err));
}
答案 0 :(得分:2)
您可以从react-native中使用Platform检查
https://facebook.github.io/react-native/docs/platform-specific-code
import { Platform } from 'react-native';
const url = Platform.OS === 'ios' ? 'https://ios.url' : 'https://android.url'