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

半腔热情 提交于 2019-11-30 20:52:58

I suggest you use this very well done library

You'll have all the info you need I think.

EDIT

You can also use some Obj-C in your AppDelegate.m file. Just add these lines :

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

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

and replace these lines :

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"NeedlIOS"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];

with these :

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

You're here passing the version as a prop to you first iOS view. That means that you can get the app version using this.props.version in your index.ios.js file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!