Retrieve CFBundleVersion from Cocos2d-x?

I’m trying to grab the CFBundleVersion from the iOS build to check whether online updates are required. Is there a straightforward way to do that through Cocos without heading into Objective-C territory?

can you parse the info.plist with an XML parser?

Is it accessible from within the app? I tried adding it to the list of copied resources and I got a build error.

We don’t have any built in functionality to get you the CFBundle version.

Option 1
You could put some quick Objective-C in AppDelegate.mm to get the CFBundleVersion and then store it or pass it to where you need to use it.

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

Option 2
If you need to check it, maybe add a #define or something to your PCH (or where ever makes sense for you). This would mean one more place to make sure you increment on new releases.

1 Like

Great suggestions, thanks. I actually went backwards (like Option 2) and did the #define method, but then added a built script that actually set the CFBundleVersion in the project so that it’s only stored in one place.