如何从iphone中的项目test-Info.plist中的标签中检索Bundle Version?

Ama*_*007 4 iphone ios

在这里,我正在粘贴我的代码,我想从我的test-Info.plist中检索Bundle版本.

@interface testViewController : UIViewController {
    UILabel *label;
}
@property(nonatomic,retain) IBOutlet    UILabel *label;

@end

@implementation testViewController

@synthesize label;

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"test-info" ofType:@"plist"];

    NSString *versionString = [NSString stringWithFormat:@"v%d", [plistData objectForKey:@"Bundle version"]];

    label.text = versionString;
}

@end
Run Code Online (Sandbox Code Playgroud)

但在我错了的地方,我仍然得到零值

Lia*_*iam 36

以下行将为您检索版本

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
Run Code Online (Sandbox Code Playgroud)

  • 另外值得注意的是:"捆绑版本"或"CFBundleVersion"等同于应用程序的内部版本号.如果你想要实际的"xy"字符串,请改用`CFBundleShortVersionString`. (7认同)
  • 这是真正的答案......不是公认的答案 (2认同)