Get build number at run-time

In the standalone settings for OSX, under “Mac App Store Options,” you can specify a bundle identifier, a version, and a build number.

Standalone OSX builds can get the version string using Application.version at run-time. However, I can’t figure out how to get the build number alongside that.

On iOS, I use a plugin with the following code to get the build number at run-time:

extern "C" {
    const char* GetBundleCode () {
        return MakeStringCopy([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] UTF8String]);
    }
}

I’m not sure how to do something equivalent on macOS. Any help appreciated.

1 Like

I wouldn’t be surprised if that code worked on macOS, have you tried?

1 Like

Hmm… right now that plugin lives in the Plugins/iOS/ folder, which automatically gets built into the resulting iOS Xcode project. I think to do something similar for macOS, I’d have to create an entirely new & separate project in Xcode, build a library/bundle there, and then import that into my game project.

As someone with limited experience in Xcode/Objective-C, and since this is literally just to show a build number in the bottom corner of our menu, I think I’m just going to set that value on one of our meta prefabs and leave it at that.

It does look like accessing the bundle version is supported in all APIs, but I’m not going to spend the extra time on it – so getting it working on macOS is left as an exercise for the reader.

@nickfourtimes1 Do you save that in Plugins/iOS as a .c, .cpp file? Or some other type altogether?

They’re .h/.mm files, which I made by just reworking the files in the Bonjour Browser Sample found at the bottom of the iOS Plugins manual.