如何在反应本机 iOS 应用程序的 运行 时间读取 Info.Plist?

How to read Info.Plist at run-time in react-native iOS app?

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

我想在应用的 "About Box" 中显示版本信息。

提前致谢,

-埃德

我建议你使用这个做得很好 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];

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