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

时间:2010-04-20 13:43:43

标签: ios iphone

这里我将我的代码粘贴到我想从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

但在我错了的时候我仍然得到空值

2 个答案:

答案 0 :(得分:36)

以下行将为您检索版本

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];

答案 1 :(得分:1)

尝试通过这样做来获取plist路径:

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