react-native - 如何在 react-native iOS 应用程序中在运行时读取 Info.Plist?

标签 react-native info.plist

在运行时,有没有办法读取CFBundleVersion从 Info.Plist ?

我想在应用程序的“关于框”中显示版本信息。

提前致谢,

-埃德

最佳答案

我建议你用这个做得很好library

我想你会得到你需要的所有信息。

编辑

您还可以在 AppDelegate.m 文件中使用一些 Obj-C。只需添加这些行:

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

NSDictionary *props = @{@"version" : version};

并替换这些行:
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"NeedlIOS"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

用这些 :
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"NeedlIOS"
                                               initialProperties:props
                                                   launchOptions:launchOptions];

您在这里将版本作为 Prop 传递给您的第一个 iOS View 。这意味着您可以使用 this.props.version 获取应用程序版本在您的 index.ios.js文件。

关于react-native - 如何在 react-native iOS 应用程序中在运行时读取 Info.Plist?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35640125/

相关文章:

ios - 出于回调 URL 的目的,在 Expo 中运行的 React Native 项目的 info.plist 在哪里?

ios - 应用程序的 Info.plist 文件应包含 NSBluetoothAlwaysUsageDescription key ,而该 key 位于 plist 文件中

ios - NSLocationWhenInUseUsageDescription 警告,但我已经添加了它

android - react native : react native undefined is not an object (evaluating 'this. _lazyCallableModules

javascript - 创建一个返回 React 组件的函数

android - 如何在 React Native (Android) 的 Facebook 登录按钮中居中放置文本?

react-native - 在 React Native ScrollView 中检测滚动结束,对齐页面

ios - 应用程序的 Info.plist 不能包含 UIRequiredDeviceCapabilities 键的值

ios - 在模拟器和物理设备上都没有在 IOS 中获得本地通知

xcode - 当我尝试通过OpenCv访问网络摄像头时,Xcode引发隐私错误