React Native:在iOS / Android版本中设置不同的变量

时间:2019-01-17 19:49:05

标签: android ios react-native

在我们的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));
  }

1 个答案:

答案 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'