why does my app crash when I call for objectForInfoDictionaryKey: CFBundleShortVersionString

457 views Asked by At

I am trying to get my version number of my app using:

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

but it crashes with this error:

[NSString stringWithUTF8String:]: NULL cString

What am I doing wrong?

1

There are 1 answers

0
jd. On

Check your info.plist to make sure short version (CFBundleShortVersionString) or (Bundle versions string, short) is set.

Your code is fine. But you can also call it this way:

NSString * version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];