0

I'm trying to retrieve some info from the main bundle:

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

I can get the CFStringRef (in debug I can see the proper value associate to the variable), but when I try to cast it to NSString my appVersion variable has "null" value (previously it was nil).

What am I doing wrong?

I'm using ARC.

EDIT: It seems that I have problem with my project, every NSString object can't be assigned even with a simple static assignment, the value of the test variable is (null)

NSString *test = @"";
Ivan
  • 666
  • 1
  • 7
  • 17

2 Answers2

1
  CFStringRef boundleVer = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
  NSString *appVersion = (__bridge NSString *)(boundleVer);

Its working fien on my side,, it is returning "2"

aBilal17
  • 2,974
  • 2
  • 17
  • 23
0

I would use that code instead of your current one to fetch the same information:


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

or

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

NOTE: I'm not sure which information you need eventually from the bundle.

holex
  • 23,961
  • 7
  • 62
  • 76