2014-10-10 62 views
0

我正在尝试从主束的一些信息:转换CFStringRef到的NSString

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {  
    CFStringRef bundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey); 
    NSString *appVersion = (__bridge NSString *)bundleVer; 
} 

我能得到CFStringRef(在调试,我可以看到正确的价值联想到的变量),但是当我尝试将其转换为NSString,我的appVersion变量具有“null”值(以前为零)。

我在做什么错?

我正在使用ARC。

编辑:看来,我有问题,我的项目,每一个的NSString对象不能即使一个简单的静态分配分配,测试变量的值(NULL)

NSString *test = @""; 
+0

可能重复的[如何将CFStringRef转换为NSString?](http://stackoverflow.com/questions/640367/how-to-convert-cfstringref-to-nsstring) – Gutblender 2014-10-10 14:17:11

+1

你的CFStringRef的值是什么?我复制了你的代码,它完全适用于我的应用程序。 – 2014-10-10 14:17:40

+0

在我的应用程序中也能正常工作.. – 2014-10-10 14:24:34

回答

1
CFStringRef boundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey); 
    NSString *appVersion = (__bridge NSString *)(boundleVer); 
在我身边

其工作FIEN ,,它返回“2”

0

我会用这些代码,而不是你当前的获取同样的信息:


NSString *_shortVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 

NSString *_version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; 

注:我不知道你从包最终需要哪些信息。