9

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

itsji10dra
  • 4,603
  • 3
  • 39
  • 59
Ed of the Mountain
  • 5,219
  • 4
  • 46
  • 54

1 Answers1

16

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.

G. Hamaide
  • 7,078
  • 2
  • 36
  • 57
  • 1
    Thank you, react-native-device-info solved the problem in minutes! Also thank your for the tip on how to pass props from AppDelegate.m to react-native. I expect that tip will be useful too! https://github.com/rebeccahughes/react-native-device-info – Ed of the Mountain Feb 26 '16 at 14:27
  • 3
    Is there a reason why this only works if I run directly from `xcode` ?. The `run-ios` command does not work. – jose920405 Jan 26 '17 at 12:51
  • 1
    I can confirm that on React Native 0.48.4 on iOS run-ios does not pass the initialProperties in. I have no idea why either! – Ben Clayton Jun 29 '18 at 08:22