PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to access environment variables located in .env - React Native

 August 21, 2022     environment-variables, intercom, intercom-ios, react-native     No comments   

Issue

I currently have .env file in which I am saving api keys and such (not actual keys in the example below):

API_URL=https://www.example.si/3000
IOS_API_KEY=738d7hfu3hffsjfsd
STRIPE_KEY=pk_fh843f483ff3f43f34
APP_ID=pk_fh843f483ff3f43f34

I need to access these keys in my AppDelegate.m file.

I've tried the following:

NSString *AppID = @(getenv("APP_ID"));

But it didn't work.I get an error : "***+[NSString stringWithUTF8String:] NULL cString" .

I cannot use variable as @"AppID" where I want to pass it in. Any ideas on how to solve this issue would be helpful.


Solution

I ended up using a library for this, called react-native-config:

https://github.com/luggit/react-native-config

and it works really well. It also has a system in place to avoid delayed (state based) caching so as soon as you save .env file there is no chance of remembering the previous state of .env file.



Answered By - Amadej Ĺ enk
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing