【问题标题】:How to read Info.Plist at run-time in react-native iOS app?如何在 react-native iOS 应用程序中运行时读取 Info.Plist?
【发布时间】:2016-02-25 22:58:40
【问题描述】:

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

我想在应用的“关于框”中显示版本信息。

提前致谢,

-埃德

【问题讨论】:

    标签: react-native info.plist


    【解决方案1】:

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

    【讨论】:

    • 谢谢,react-native-device-info 分分钟解决问题!还要感谢您关于如何将道具从 AppDelegate.m 传递到 react-native 的提示。我希望这个技巧也很有用! github.com/rebeccahughes/react-native-device-info
    • 只有当我直接从xcode 运行时,这是否有效? run-ios 命令不起作用。
    • 我可以确认,在 iOS 上的 React Native 0.48.4 上,run-ios 没有传入 initialProperties。我也不知道为什么!
    猜你喜欢
    • 2019-08-26
    • 2016-05-29
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 2018-06-11
    • 2016-12-10
    • 2021-11-11
    相关资源
    最近更新 更多