iOS Question How to get ApplicationLabel and Version at runtime?

davemorris

Active Member
Licensed User
Longtime User
Hi all,
Maybe I'm being slow, but I can't seem to find any way to get the app's name and version at runtime?
I.e. the values of the Project Attributes #ApplicationLabel and #Version that are set in the Main module.

In B4A I would do it by calling Application.LabelName and Application.VersionName, but the B4i equivalent Application object doesn't appear to have the relevant properties?
 

Pendrush

Well-Known Member
Licensed User
Longtime User
B4X:
Sub AppName As String 
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim name As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleDisplayName"))
   Return name 
End Sub

Sub AppVersion As String
   Dim no As NativeObject
   no = no.Initialize("NSBundle").RunMethod("mainBundle", Null)
   Dim version As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleShortVersionString"))
   Return version 
End Sub
 
Upvote 0

TheRealMatze

Active Member
Licensed User
Hi,
is there any new version? This code will not work here...

B4X:
Error description: Current declaration does not match previous one.
Previous: {Type=Label,Rank=0, RemoteObject=True}
Current: {Type=Object,Rank=0, RemoteObject=True}
Error occurred on line: 34
Dim version As Object = no.RunMethod("objectForInfoDictionaryKey:", Array("CFBundleShortVersionString"))

Regards
Matze
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User

It doesnt have anything to do with the code.
The error message is suggesting there is a variable called version already there, and there is new variable with the type Object, also in code.
Change one and try again
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…