Is there a way to read settings from app.json in Java/Objective C?

Hi,

I have an ejected app, and I’m using the react-native-intercom library. That library has you modify your Java/ObjectiveC code, so you can tell it what api key to use.

@Override
  public void onCreate() {
    super.onCreate();
    Intercom.initialize(this, "whatever", "whatever");
  }

I can make that change, but I’d rather not hard-code the api key.

It would make more sense to put it where I’m putting other credentials, which is in the app.json file. I have separate app.json files for staging & production, so it’s easy to switch between them.

Anyway, if I put that apiKey in app.json, is there a way to get that value on the Java/ObjectiveC side?

I thought there must be, since presumably you must read out values from the app.json on the native side occasionally, but I can’t seem to find what it might be.

Any suggestions?

Two things you could do:
(1) Add app.json to your app bundle. Then use a JSON parser/library to read it in and then get the keys from there.
(2) Add something to your build process that generates a Java file/class based on the contents of app.json and gives you the key that way.

Personally I would probably just hard code it in for now because that would take a lot less time, but I see how that doesn’t feel clean.

The main issue with the hard-coded API key was that it becomes too difficult to quickly switch between staging & production environments.

Thanks, I guess I’ll try something like that then, hopefully it doesn’t take too long.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.