Way to get app version?

Is there a way to access the app major and minor version numbers in an iOS app? In a desktop app I have:

AppVersion = Str(App.MajorVersion) + “.” + Str(App.MinorVersion)

This didn’t work for an iOS app and I haven’t found a way yet other than adding an App property for it that duplicates the project settings.

[quote=157237:@Peter Mitchell]Is there a way to access the app major and minor version numbers in an iOS app? In a desktop app I have:

AppVersion = Str(App.MajorVersion) + “.” + Str(App.MinorVersion)

This didn’t work for an iOS app and I haven’t found a way yet other than adding an App property for it that duplicates the project settings.[/quote]

What about reading the Info.plist file in the bundle ? These are simply XML keys. It works for iOS.

In Mac OS X, the constant approach is usually preferable, since the signing process makes the info.plist not text anymore.

[quote=157250:@Michel Bujardet]What about reading the Info.plist file in the bundle ? These are simply XML keys. It works for iOS.

In Mac OS X, the constant approach is usually preferable, since the signing process makes the info.plist not text anymore.[/quote]

If you want to read it at runtime, use declares to NSBundle. There’s no guarantees that the Info.plist file will always be an XML property list.

With declares (Add constant “FoundationLib = Foundation.framework”):

Function getAppVersion() As Text
  declare function NSClassFromString lib FoundationLib (clsName as CFStringRef) as ptr
  declare function mainBundle lib FoundationLib selector "mainBundle" (clsRef as ptr) as ptr
  declare function objectForInfoDictionaryKey lib FoundationLib selector "objectForInfoDictionaryKey:" _
  (obj_id as ptr, key as CFStringRef) as CFStringRef
  
  Return objectForInfoDictionaryKey(mainBundle(NSClassFromString("NSBundle")), "CFBundleShortVersionString")
End Function
1 Like

[quote=157310:@Jason King]With declares (Add constant “FoundationLib = Foundation.framework”):

[code]
Function getAppVersion() As Text
declare function NSClassFromString lib FoundationLib (clsName as CFStringRef) as ptr
declare function mainBundle lib FoundationLib selector “mainBundle” (clsRef as ptr) as ptr
declare function objectForInfoDictionaryKey lib FoundationLib selector “objectForInfoDictionaryKey:” _
(obj_id as ptr, key as CFStringRef) as CFStringRef

Return objectForInfoDictionaryKey(mainBundle(NSClassFromString(“NSBundle”)), “CFBundleShortVersionString”)
End Function
[/code][/quote]

Thank you :slight_smile:

You’re welcome :slight_smile:

Thanks for all the responses.

For this instead of using a declare I simply use a pre build script:
I have defined a constant at app level kVersion as text
my pre build script is simply:

  dim v() as string
  v.append PropertyValue("App.MajorVersion")
  v.append "."
  v.append PropertyValue("App.MinorVersion")
  v.append "."
  v.append PropertyValue("App.BugVersion")
  v.append " ("
  v.append PropertyValue("App.NonReleaseVersion")
  v.append ")"
  
  dim m as string=join(v,"")
  ConstantValue("App.kVersion")=m

obviously you can create the constants based on your needs.

I am trying to get Antonio’s method to work and my script does not seem to affect the value of App.kVersion
I am pretty sure the script is running. (maybe not at the right time?)

My script must run BEFORE build and a constant named kVersion (string) must exist in App

I can’t figure it out. Please tell me.
How do I get this script to run before build?

Create the script as build step
drag it to the target
drag it before build item

Thanks!
I got it working.
Part of my problem was I renamed “app” so I had to declare that name.