这里我将我的代码粘贴到我想从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
但在我错了的时候我仍然得到空值
答案 0 :(得分:36)
以下行将为您检索版本
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
答案 1 :(得分:1)
尝试通过这样做来获取plist路径:
NSString *path = [[NSBundle mainBundle] pathForResource:@"test-info" ofType:@"plist"];