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

问题描述:

在运行时,有没有办法从Info.Plist中读取CFBundleVersion如何在运行时在反应本机iOS应用程序中读取Info.Plist?

我想在应用程序的“About Box”中显示版本信息。

由于提前,

-Ed

我建议你使用这个做得非常好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获取应用程序版本。

+0

谢谢react-native-device-info在几分钟内解决了问题!同时感谢你的提示,告诉你如何从AppDelegate.m传递道具来反应原生。我希望提示也会有用! https://github.com/rebeccahughes/react-native-device-info –

+1

是否有一个原因,只有当我直接从'xcode'运行时,这才有效? 'run-ios'命令不起作用。 – jose920405