Search Unity

Get build number at run-time

Discussion in 'macOS' started by nickfourtimes, Apr 17, 2019.

  1. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    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:
    Code (CSharp):
    1.  
    2. extern "C" {
    3.     const char* GetBundleCode () {
    4.         return MakeStringCopy([[[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey] UTF8String]);
    5.     }
    6. }
    I'm not sure how to do something equivalent on macOS. Any help appreciated.
     
    Coeur_EF likes this.
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I wouldn't be surprised if that code worked on macOS, have you tried?
     
    nickfourtimes likes this.
  3. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    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.
     
  4. jakemoves

    jakemoves

    Joined:
    Jan 7, 2013
    Posts:
    1
    @nickfourtimes Do you save that in Plugins/iOS as a .c, .cpp file? Or some other type altogether?
     
  5. nickfourtimes

    nickfourtimes

    Joined:
    Oct 13, 2010
    Posts:
    219
    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.