【问题标题】:Using environment variable in react-native swift在 react-native swift 中使用环境变量
【发布时间】:2020-05-09 23:48:30
【问题描述】:

我正在开发 React-Native 应用程序,并希望配置可以与 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"];

【问题讨论】:

    标签: ios swift react-native


    【解决方案1】:

    看看react-native-config 库。它允许您访问在原生部分的 .env 文件中定义的环境变量,以及应用程序的 JavaScript 部分。

    【讨论】:

      猜你喜欢
      • 2020-02-04
      • 2016-01-12
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多