【问题标题】:How do I render a varaible or data from the info.plist in VS code? (React-Native)如何在 VS 代码中渲染来自 info.plist 的变量或数据? (反应原生)
【发布时间】:2021-08-24 09:58:08
【问题描述】:

我正在使用 VS 代码在 ios 中构建一个 react-native 应用程序。

我知道如何使用 Xcode 将密钥添加到 info.plist 文件中,现在我可以在 VS 文件系统的 info.plist 文件中看到该密钥显示在我的屏幕?

例如 SERVICE_KEY = "Hello World"

如何使用 VS 代码而不是 Xcode 让“Hello World”显示在屏幕上。

我正在考虑类似下面的内容,但显然它不正确

SERVICE_KEY 是我要显示的关键数据

```import React from 'react';
import {StyleSheet, Text, View, SafeAreaView} from 'react-native';
// import 'info.plist';
// import 'strings.xml';

import {SERVICE_KEY} from 'rnFinal/ios/rnFinal/info.plist';


const Key = () => {
  return (
    <SafeAreaView>
      <View>
        {/* <Text>{SERVICE_KEY}</Text> */}
        <Text>I am going to be a key</Text>
      </View>
    </SafeAreaView>
  );
};

export default Key;

const styles = StyleSheet.create({});```

下面是 info.plist

``` <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
//lots of key values...
    <key>Service_Key</key>
    <string>$(SERVICE_KEY)</string>
</dict>
</plist>```

附带问题是否有人推荐任何好的资源来在 VS 代码中构建 react native 而不是使用 X'每次升级都会中断'代码?

感谢您的帮助!

【问题讨论】:

    标签: ios xcode react-native visual-studio-code


    【解决方案1】:

    您无法从本机端访问数据 以相反的方式执行此操作可以达到什么目的。

    例如:在js端创建一个文件并在那里添加键

    SERVICE_KEY="hello world"
    

    然后在 info.plist 和你的 js 代码中使用它。

    关于这个概念的详细理解,看看

    react-native-config

    【讨论】:

    • 所以像你一样在 env 文件中创建数据,然后将其提供给 plist 文件以及你想在哪里显示它?谢谢哥们!
    • 如果它解决了您的问题,请标记答案正确:P
    猜你喜欢
    • 2019-01-07
    • 2018-02-03
    • 2019-10-07
    • 1970-01-01
    • 2021-12-28
    • 2020-09-05
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多