ios - 在 react-native swift 中使用环境变量
问题描述
我正在开发 React-Native App 并希望配置可以与 iOS 应用程序和 Android 共享的环境变量。
文档要求我在 AppDelegate.m 中添加这一行
[GMSServices provideAPIKey:@"Azzz8"];`
这Azzz8
将是我的 api 密钥。现在我想将它传递到环境文件中并从那里传递(到 ios 和 android)。知道我该怎么做吗?
这就是我的 AppDelegate.m 代码的样子
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "AppDelegate.h"
#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#import <GoogleMaps/GoogleMaps.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* Firebasee App Config */
[FIRApp configure];
[GMSServices provideAPIKey:@"1234"];
解决方案
看看react-native-config库。它允许您访问在本机部分的.env文件中定义的环境变量,以及应用程序的 JavaScript 部分。
推荐阅读
- php - Smarty (PHP) 数学问题与四舍五入的结果。Prestashop
- machine-learning - 如何区分手写与背景
- spring - 将轮询器添加到 SFTP 出站网关
- python - 考虑到索引位置,首先获取两个数组的 nan
- nativescript - NativeScript Vue 发送带有表单数据的请求(multipart/form-data)
- nosql - 如何在 DynamoDB 中为制造商建模
- python - AWS serverless 函数运行时环境使用的是哪个 python3.6 补丁版本?
- flutter - 如何使用 Flutter 应用程序和 Firebase 保存信用卡以供以后在 Stripe 支付中使用?
- sql - 按聚合函数 SQL 分组
- javascript - 在 C#/ASP.NET/Razor html Web 应用程序中实现 WebcamJS