1

I'm building a react native iOS app, and would like to:

1) Display the app's current version from the package.json file in the app itself.

Specifically: Now that I've implemented codepush, I want to display the current app version on the Settings page, so that app users can tell if their app has been upgraded. I currently set the version number in the package.json file and use this shell script to propagate that to the xcode project. If there's a better way to manage/update a projects version number, please let me know!

2) Execute certain .js code based on build variables from xcode.

I have three build configurations (Debug, Staging, Release) setup in xcode, and I would like to specify the updateDialog: true flag to codepush only for Staging builds. I would also like to display on the settings page whether this is a Debug, Staging or Release build.

What is the best way to accomplish these things?

Are there best practices for setting/syncing a project's version number and accessing it within the app, or is this stuff usually just coded by hand?

Fwiw, this answer is relevant, but doesn't say what specific environment variables xcode defines that would help me here, and doesn't speak to the versioning question.

Justin H
  • 13
  • 1
  • 5

1 Answers1

1
async function getAppVersion() {
  const {appVersion} = await codePush.getConfiguration();

  const meta = await codePush.getUpdateMetadata();
  if (!meta) return {appVersion};

  const {label} = meta;
  return {appVersion, label};
}

label will contain codepush release label (by default v1, v2...)

For env variables react-native-config maybe can help you. I am using fastlane with increment_build_number (iOS) and handmade fastlane code (Android) to autoincrement build number. To be honest I'm on my own in best practice search.

farwayer
  • 3,872
  • 3
  • 21
  • 23
  • Thanks - very helpful @farwayer. One solution I had been imagining to this is to have some sort of self-made build script that gets the version from a single, definitive source (say, the package.json file) and propagates it to an env.js file, the xcode project, etc. I hesitate to do that, mostly because any time I am custom coding something that seems like a very common use scenario, I wonder if there isn't a better solution already made and/or established best practices. Eager to hear how people do this in general with JS projects, with or without codepush. – Justin H Jul 07 '17 at 16:13
  • I also just found [babel-plugin-inline-json-import](https://www.npmjs.com/package/babel-plugin-inline-json-import), which may help solve how to get the package.json data into the app without doing an explicit file read. – Justin H Jul 07 '17 at 16:16
  • @farwayer: could you please share your handmade Android implementation for fastlane? – suther Oct 18 '18 at 08:36
  • @suther https://gist.github.com/farwayer/64370e04808d53e7c19f0201a954d9b0 It's old code so i'm not sure it is working now and it is best solution – farwayer Oct 18 '18 at 23:10