我正在尝试从主包中检索一些信息:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
CFStringRef bundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
NSString *appVersion = (__bridge NSString *)bundleVer;
}
我可以获得 CFStringRef(在调试中我可以看到与该变量关联的正确值),但是当我尝试将其转换为 NSString 时,我的 appVersion 变量具有“null”值(以前为 nil)。
我做错了什么?
我正在使用 ARC。
编辑:我的项目似乎有问题,即使使用简单的静态赋值,也无法分配每个 NSString 对象,测试变量的值为 (null)
NSString *test = @"";
最佳答案
CFStringRef boundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
NSString *appVersion = (__bridge NSString *)(boundleVer);
它在我这边工作,它正在返回“2”
关于objective-c - 将 CFStringRef 转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26301440/