John
John

Reputation: 612

React Native: set different variable in iOS/Android builds

In our React Native app, we have a link that directs the user to download a newer version of the app. The problem is that, in the Android build, this ought to point to the Play Store. In the iOS build, the link ought to point to the App store. Is there a way I can insert the appropriate links at build time? Here is the code where we use the link.

 _handleDownloadPress = () => {
    const url = 'https://xxxx.app.link/example';
    Linking.canOpenURL(url).then(supported => {
      supported && Linking.openURL(url);
    }, (err) => console.log(err));
  }

Upvotes: 0

Views: 206

Answers (1)

Andrew
Andrew

Reputation: 28539

You can use the Platform check from react-native

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'

Upvotes: 2

Related Questions