Search code examples
iosdelphipascal

ask for version IOS in delphi


The code that i use to get the version of the ios app dont work. i dont know what i am doing wrong. This is the code:

function GetIOSVesion : string;
{$IFDEF IOS}
 var
  AppKey: Pointer;
  AppBundle: NSBundle;
  BuildStr : NSString;
begin
  Result := '?';
  try
    AppKey := (StrToNSStr('CFBundleVersion') as ILocalObject).GetObjectID;

    AppBundle := TNSBundle.Wrap(TNSBundle.OCClass.mainBundle);
    BuildStr := TNSString.Wrap(AppBundle.infoDictionary.objectForKey(AppKey));
    Result := UTF8ToString(BuildStr.UTF8String);

  except
  end;
end;
{$ENDIF}

The erros i get are : Undeclared identifier : NSBundle Undeclared identifier : NSString Undeclared identifier : strToNSStr Undeclared identifier : ILocalObject

the uses for ios are:

    {$IFDEF APPLE}
 uses
  {$IFDEF IOS}
   iOSapi.Foundation,
  {$ELSE}
  Macapi.Foundation,
  {$ENDIF}
  Macapi.Helpers,
  Macapi.ObjectiveC;
{$ENDIF}

Solution

  • NSBundle is defined in Macapi.Foundation. mac API is not IOS. So either you must add Macapi.Foundation to the uses clause or you cannot use NSBundle in an iOS application or it is missing from the RTL.