Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

At run time, is there a way to read CFBundleVersion from the Info.Plist ?

I want to display the version info in the app's "About Box".

Thanks in advance,

-Ed

like image 203
Ed of the Mountain Avatar asked Feb 25 '16 22:02

Ed of the Mountain


1 Answers

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.

like image 108
G. Hamaide Avatar answered Nov 15 '22 04:11

G. Hamaide