Jump to content
LairdTurnerSpecial

Build a iOS Static library to use in Delphi

Recommended Posts

Hello!

 

I want to create a static library in Xcode an then use it in Delphi.
Then I've imported the library via

const
  LIB_Name = 'libDName.a';
  //
const
  LIB_Name = 'libDName.a';
function deviceName: NSString; cdecl; external LIB_Name name 'deviceName' dependency 'c++'; { do not localize }

But when I want to use the function with 

 

Name := NSStringToString(deviceName);

 

I get the following error:

[DCC Fehler] E2597 Undefined symbols for architecture arm64:
    Error: "_deviceName", referenced from:      __ZN4Main10deviceNameEv in Main.o;
  ld: symbol(s) not found for architecture arm64

 

Any suggestions? Thanks!

 

 

regards

 

Share this post


Link to post

Try just:

const
  LIB_Name = 'libDName.a';
function deviceName: NSString; cdecl; external LIB_Name;

You need to add the .a directory to your project's Search Path. If that doesn't work, try replacing NSString with pointer and converting later manually.

Edited by vfbb

Share this post


Link to post

If you just want the device model name, I made a function just for it:

 

uses
  System.SysUtils,
  System.Generics.Collections,
  System.Generics.Defaults,
  Posix.SysSysctl,
  Posix.StdDef;

  function GetDeviceModelString: string;

    // Pretty names list in https://gist.github.com/adamawolf/3048717
    function GetPrettyName(const AMachine: string): string;
    type
      TAppleDevice = record
        Machine: string;
        Name: string;
      end;
    const
      AppleDevices: array[0..145] of TAppleDevice = (
        (Machine: 'arm64'; Name: 'iPhone Simulator'),
        (Machine: 'i386'; Name: 'iPhone Simulator'),
        (Machine: 'ipad1,1'; Name: 'iPad'),
        (Machine: 'ipad1,2'; Name: 'iPad 3G'),
        (Machine: 'ipad11,1'; Name: 'iPad mini 5th Gen (WiFi)'),
        (Machine: 'ipad11,2'; Name: 'iPad mini 5th Gen'),
        (Machine: 'ipad11,3'; Name: 'iPad Air 3rd Gen (WiFi)'),
        (Machine: 'ipad11,4'; Name: 'iPad Air 3rd Gen'),
        (Machine: 'ipad11,6'; Name: 'iPad 8th Gen (WiFi)'),
        (Machine: 'ipad11,7'; Name: 'iPad 8th Gen (WiFi+Cellular)'),
        (Machine: 'ipad13,1'; Name: 'iPad air 4th Gen (WiFi)'),
        (Machine: 'ipad13,10'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,11'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,2'; Name: 'iPad air 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad13,4'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,5'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,6'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,7'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,8'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,9'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad2,1'; Name: '2nd Gen iPad'),
        (Machine: 'ipad2,2'; Name: '2nd Gen iPad GSM'),
        (Machine: 'ipad2,3'; Name: '2nd Gen iPad CDMA'),
        (Machine: 'ipad2,4'; Name: '2nd Gen iPad New Revision'),
        (Machine: 'ipad2,5'; Name: 'iPad mini'),
        (Machine: 'ipad2,6'; Name: 'iPad mini GSM+LTE'),
        (Machine: 'ipad2,7'; Name: 'iPad mini CDMA+LTE'),
        (Machine: 'ipad3,1'; Name: '3rd Gen iPad'),
        (Machine: 'ipad3,2'; Name: '3rd Gen iPad CDMA'),
        (Machine: 'ipad3,3'; Name: '3rd Gen iPad GSM'),
        (Machine: 'ipad3,4'; Name: '4th Gen iPad'),
        (Machine: 'ipad3,5'; Name: '4th Gen iPad GSM+LTE'),
        (Machine: 'ipad3,6'; Name: '4th Gen iPad CDMA+LTE'),
        (Machine: 'ipad4,1'; Name: 'iPad Air (WiFi)'),
        (Machine: 'ipad4,2'; Name: 'iPad Air (GSM+CDMA)'),
        (Machine: 'ipad4,3'; Name: '1st Gen iPad Air (China)'),
        (Machine: 'ipad4,4'; Name: 'iPad mini Retina (WiFi)'),
        (Machine: 'ipad4,5'; Name: 'iPad mini Retina (GSM+CDMA)'),
        (Machine: 'ipad4,6'; Name: 'iPad mini Retina (China)'),
        (Machine: 'ipad4,7'; Name: 'iPad mini 3 (WiFi)'),
        (Machine: 'ipad4,8'; Name: 'iPad mini 3 (GSM+CDMA)'),
        (Machine: 'ipad4,9'; Name: 'iPad Mini 3 (China)'),
        (Machine: 'ipad5,1'; Name: 'iPad mini 4 (WiFi)'),
        (Machine: 'ipad5,2'; Name: '4th Gen iPad mini (WiFi+Cellular)'),
        (Machine: 'ipad5,3'; Name: 'iPad Air 2 (WiFi)'),
        (Machine: 'ipad5,4'; Name: 'iPad Air 2 (Cellular)'),
        (Machine: 'ipad6,11'; Name: 'iPad (2017)'),
        (Machine: 'ipad6,12'; Name: 'iPad (2017)'),
        (Machine: 'ipad6,3'; Name: 'iPad Pro (9.7 inch, WiFi)'),
        (Machine: 'ipad6,4'; Name: 'iPad Pro (9.7 inch, WiFi+LTE)'),
        (Machine: 'ipad6,7'; Name: 'iPad Pro (12.9 inch, WiFi)'),
        (Machine: 'ipad6,8'; Name: 'iPad Pro (12.9 inch, WiFi+LTE)'),
        (Machine: 'ipad7,1'; Name: 'iPad Pro 2nd Gen (WiFi)'),
        (Machine: 'ipad7,11'; Name: 'iPad 7th Gen 10.2-inch (WiFi)'),
        (Machine: 'ipad7,12'; Name: 'iPad 7th Gen 10.2-inch (WiFi+Cellular)'),
        (Machine: 'ipad7,2'; Name: 'iPad Pro 2nd Gen (WiFi+Cellular)'),
        (Machine: 'ipad7,3'; Name: 'iPad Pro 10.5-inch'),
        (Machine: 'ipad7,4'; Name: 'iPad Pro 10.5-inch'),
        (Machine: 'ipad7,5'; Name: 'iPad 6th Gen (WiFi)'),
        (Machine: 'ipad7,6'; Name: 'iPad 6th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,1'; Name: 'iPad Pro 11 inch 3rd Gen (WiFi)'),
        (Machine: 'ipad8,10'; Name: 'iPad Pro 11 inch 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,11'; Name: 'iPad Pro 12.9 inch 4th Gen (WiFi)'),
        (Machine: 'ipad8,12'; Name: 'iPad Pro 12.9 inch 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,2'; Name: 'iPad Pro 11 inch 3rd Gen (1TB, WiFi)'),
        (Machine: 'ipad8,3'; Name: 'iPad Pro 11 inch 3rd Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,4'; Name: 'iPad Pro 11 inch 3rd Gen (1TB, WiFi+Cellular)'),
        (Machine: 'ipad8,5'; Name: 'iPad Pro 12.9 inch 3rd Gen (WiFi)'),
        (Machine: 'ipad8,6'; Name: 'iPad Pro 12.9 inch 3rd Gen (1TB, WiFi)'),
        (Machine: 'ipad8,7'; Name: 'iPad Pro 12.9 inch 3rd Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,8'; Name: 'iPad Pro 12.9 inch 3rd Gen (1TB, WiFi+Cellular)'),
        (Machine: 'ipad8,9'; Name: 'iPad Pro 11 inch 4th Gen (WiFi)'),
        (Machine: 'iphone1,1'; Name: 'iPhone'),
        (Machine: 'iphone1,2'; Name: 'iPhone 3G'),
        (Machine: 'iphone10,1'; Name: 'iPhone 8'),
        (Machine: 'iphone10,2'; Name: 'iPhone 8 Plus'),
        (Machine: 'iphone10,3'; Name: 'iPhone X Global'),
        (Machine: 'iphone10,4'; Name: 'iPhone 8'),
        (Machine: 'iphone10,5'; Name: 'iPhone 8 Plus'),
        (Machine: 'iphone10,6'; Name: 'iPhone X GSM'),
        (Machine: 'iphone11,2'; Name: 'iPhone XS'),
        (Machine: 'iphone11,4'; Name: 'iPhone XS Max'),
        (Machine: 'iphone11,6'; Name: 'iPhone XS Max Global'),
        (Machine: 'iphone11,8'; Name: 'iPhone XR'),
        (Machine: 'iphone12,1'; Name: 'iPhone 11'),
        (Machine: 'iphone12,3'; Name: 'iPhone 11 Pro'),
        (Machine: 'iphone12,5'; Name: 'iPhone 11 Pro Max'),
        (Machine: 'iphone12,8'; Name: 'iPhone SE 2nd Gen'),
        (Machine: 'iphone13,1'; Name: 'iPhone 12 Mini'),
        (Machine: 'iphone13,2'; Name: 'iPhone 12'),
        (Machine: 'iphone13,3'; Name: 'iPhone 12 Pro'),
        (Machine: 'iphone13,4'; Name: 'iPhone 12 Pro Max'),
        (Machine: 'iphone2,1'; Name: 'iPhone 3GS'),
        (Machine: 'iphone3,1'; Name: 'iPhone 4'),
        (Machine: 'iphone3,2'; Name: 'iPhone 4 GSM Rev A'),
        (Machine: 'iphone3,3'; Name: 'iPhone 4 CDMA'),
        (Machine: 'iphone4,1'; Name: 'iPhone 4S'),
        (Machine: 'iphone5,1'; Name: 'iPhone 5 (GSM)'),
        (Machine: 'iphone5,2'; Name: 'iPhone 5 (GSM+CDMA)'),
        (Machine: 'iphone5,3'; Name: 'iPhone 5C (GSM)'),
        (Machine: 'iphone5,4'; Name: 'iPhone 5C (Global)'),
        (Machine: 'iphone6,1'; Name: 'iPhone 5S (GSM)'),
        (Machine: 'iphone6,2'; Name: 'iPhone 5S (Global)'),
        (Machine: 'iphone7,1'; Name: 'iPhone 6 Plus'),
        (Machine: 'iphone7,2'; Name: 'iPhone 6'),
        (Machine: 'iphone8,1'; Name: 'iPhone 6s'),
        (Machine: 'iphone8,2'; Name: 'iPhone 6s Plus'),
        (Machine: 'iphone8,4'; Name: 'iPhone SE (GSM)'),
        (Machine: 'iphone9,1'; Name: 'iPhone 7'),
        (Machine: 'iphone9,2'; Name: 'iPhone 7 Plus'),
        (Machine: 'iphone9,3'; Name: 'iPhone 7'),
        (Machine: 'iphone9,4'; Name: 'iPhone 7 Plus'),
        (Machine: 'ipod1,1'; Name: '1st Gen iPod'),
        (Machine: 'ipod2,1'; Name: '2nd Gen iPod'),
        (Machine: 'ipod3,1'; Name: '3rd Gen iPod'),
        (Machine: 'ipod4,1'; Name: '4th Gen iPod'),
        (Machine: 'ipod5,1'; Name: '5th Gen iPod'),
        (Machine: 'ipod7,1'; Name: '6th Gen iPod'),
        (Machine: 'ipod9,1'; Name: '7th Gen iPod'),
        (Machine: 'watch1,1'; Name: 'Apple Watch 38mm case'),
        (Machine: 'watch1,2'; Name: 'Apple Watch 42mm case'),
        (Machine: 'watch2,3'; Name: 'Apple Watch Series 2 38mm case'),
        (Machine: 'watch2,4'; Name: 'Apple Watch Series 2 42mm case'),
        (Machine: 'watch2,6'; Name: 'Apple Watch Series 1 38mm case'),
        (Machine: 'watch2,7'; Name: 'Apple Watch Series 1 42mm case'),
        (Machine: 'watch3,1'; Name: 'Apple Watch Series 3 38mm case (GPS+Cellular)'),
        (Machine: 'watch3,2'; Name: 'Apple Watch Series 3 42mm case (GPS+Cellular)'),
        (Machine: 'watch3,3'; Name: 'Apple Watch Series 3 38mm case (GPS)'),
        (Machine: 'watch3,4'; Name: 'Apple Watch Series 3 42mm case (GPS)'),
        (Machine: 'watch4,1'; Name: 'Apple Watch Series 4 40mm case (GPS)'),
        (Machine: 'watch4,2'; Name: 'Apple Watch Series 4 44mm case (GPS)'),
        (Machine: 'watch4,3'; Name: 'Apple Watch Series 4 40mm case (GPS+Cellular)'),
        (Machine: 'watch4,4'; Name: 'Apple Watch Series 4 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,1'; Name: 'Apple Watch Series 5 40mm case (GPS)'),
        (Machine: 'watch5,10'; Name: 'Apple Watch SE 44mm case (GPS)'),
        (Machine: 'watch5,11'; Name: 'Apple Watch SE 40mm case (GPS+Cellular)'),
        (Machine: 'watch5,12'; Name: 'Apple Watch SE 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,2'; Name: 'Apple Watch Series 5 44mm case (GPS)'),
        (Machine: 'watch5,3'; Name: 'Apple Watch Series 5 40mm case (GPS+Cellular)'),
        (Machine: 'watch5,4'; Name: 'Apple Watch Series 5 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,9'; Name: 'Apple Watch SE 40mm case (GPS)'),
        (Machine: 'watch6,1'; Name: 'Apple Watch Series 6 40mm case (GPS)'),
        (Machine: 'watch6,2'; Name: 'Apple Watch Series 6 44mm case (GPS)'),
        (Machine: 'watch6,3'; Name: 'Apple Watch Series 6 40mm case (GPS+Cellular)'),
        (Machine: 'watch6,4'; Name: 'Apple Watch Series 6 44mm case (GPS+Cellular)'),
        (Machine: 'x86_64'; Name: 'iPhone Simulator'));
    var
      LDevice: TAppleDevice;
      LIndex: Integer;
      LStringComparer: IComparer<string>;
    begin
      LDevice.Machine := AMachine.ToLower;
      LDevice.Name := '';
      LStringComparer := TComparer<string>.Default;
      if TArray.BinarySearch<TAppleDevice>(AppleDevices, LDevice, LIndex, TComparer<TAppleDevice>.Construct(
        function(const ALeft, ARight: TAppleDevice): Integer
        begin
          Result := LStringComparer.Compare(ALeft.Machine, ARight.Machine);
        end)) then
      begin
        Result := AppleDevices[LIndex].Name;
      end
      else if AMachine.IsEmpty then
        Result := ''
      else
      begin
        {$IFDEF DEBUG}
        for LIndex := 0 to Length(AppleDevices)-1 do
          if (AppleDevices[LIndex].Machine <> AppleDevices[LIndex].Machine.ToLower) then
            raise Exception.Create('Apple device list is wrong (the "Machine" field don''t allow upper case)');
        for LIndex := 1 to Length(AppleDevices)-1 do
          if LStringComparer.Compare(AppleDevices[LIndex-1].Machine, AppleDevices[LIndex].Machine) <> -1 then
            raise Exception.Create('Apple device list is wrong (it isn''t ordered or have duplicate item)');
        {$ENDIF}
        Result := '[' + AMachine + ']';
      end;
    end;

  var
    LSize: size_t;
    LDeviceModelBuffer: array of Byte;
  begin
    sysctlbyname('hw.machine', nil, @LSize, nil, 0);
    if LSize > 0 then
    begin
      SetLength(LDeviceModelBuffer, LSize);
      sysctlbyname('hw.machine', @LDeviceModelBuffer[0], @LSize, nil, 0);
      Result := GetPrettyName(UTF8ToString(MarshaledAString(LDeviceModelBuffer)));
    end
    else
      Result := '';
  end;

 

Edited by vfbb
Updated the devices pretty name

Share this post


Link to post
7 hours ago, vfbb said:

Try just:


const
  LIB_Name = 'libDName.a';
function deviceName: NSString; cdecl; external LIB_Name;

You need to add the .a directory to your project's Search Path. If that doesn't work, try replacing NSString with pointer and converting later manually.

The library is found! For testing I've copied it directly to the root of the project. If it was'nt I would get other failures.
I've tried to change the result type but I get the same failure

[DCC Fehler] E2597 Undefined symbols for architecture arm64:
    Error: "_deviceName", referenced from:      __ZN4Main10deviceNameEv in Main.o;
  ld: symbol(s) not found for architecture arm64

 

Is there a trick or copiler setting in xcode to set?

Share this post


Link to post
7 hours ago, vfbb said:

If you just want the device model name, I made a function just for it:

 


uses
  System.SysUtils,
  System.Generics.Collections,
  System.Generics.Defaults,
  Posix.SysSysctl,
  Posix.StdDef;

  function GetDeviceModelString: string;

    // Pretty names list in https://gist.github.com/adamawolf/3048717
    function GetPrettyName(const AMachine: string): string;
    type
      TAppleDevice = record
        Machine: string;
        Name: string;
      end;
    const
      AppleDevices: array[0..145] of TAppleDevice = (
        (Machine: 'arm64'; Name: 'iPhone Simulator'),
        (Machine: 'i386'; Name: 'iPhone Simulator'),
        (Machine: 'ipad1,1'; Name: 'iPad'),
        (Machine: 'ipad1,2'; Name: 'iPad 3G'),
        (Machine: 'ipad11,1'; Name: 'iPad mini 5th Gen (WiFi)'),
        (Machine: 'ipad11,2'; Name: 'iPad mini 5th Gen'),
        (Machine: 'ipad11,3'; Name: 'iPad Air 3rd Gen (WiFi)'),
        (Machine: 'ipad11,4'; Name: 'iPad Air 3rd Gen'),
        (Machine: 'ipad11,6'; Name: 'iPad 8th Gen (WiFi)'),
        (Machine: 'ipad11,7'; Name: 'iPad 8th Gen (WiFi+Cellular)'),
        (Machine: 'ipad13,1'; Name: 'iPad air 4th Gen (WiFi)'),
        (Machine: 'ipad13,10'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,11'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,2'; Name: 'iPad air 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad13,4'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,5'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,6'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,7'; Name: 'iPad Pro 11 inch 3rd Gen'),
        (Machine: 'ipad13,8'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad13,9'; Name: 'iPad Pro 12.9 inch 5th Gen'),
        (Machine: 'ipad2,1'; Name: '2nd Gen iPad'),
        (Machine: 'ipad2,2'; Name: '2nd Gen iPad GSM'),
        (Machine: 'ipad2,3'; Name: '2nd Gen iPad CDMA'),
        (Machine: 'ipad2,4'; Name: '2nd Gen iPad New Revision'),
        (Machine: 'ipad2,5'; Name: 'iPad mini'),
        (Machine: 'ipad2,6'; Name: 'iPad mini GSM+LTE'),
        (Machine: 'ipad2,7'; Name: 'iPad mini CDMA+LTE'),
        (Machine: 'ipad3,1'; Name: '3rd Gen iPad'),
        (Machine: 'ipad3,2'; Name: '3rd Gen iPad CDMA'),
        (Machine: 'ipad3,3'; Name: '3rd Gen iPad GSM'),
        (Machine: 'ipad3,4'; Name: '4th Gen iPad'),
        (Machine: 'ipad3,5'; Name: '4th Gen iPad GSM+LTE'),
        (Machine: 'ipad3,6'; Name: '4th Gen iPad CDMA+LTE'),
        (Machine: 'ipad4,1'; Name: 'iPad Air (WiFi)'),
        (Machine: 'ipad4,2'; Name: 'iPad Air (GSM+CDMA)'),
        (Machine: 'ipad4,3'; Name: '1st Gen iPad Air (China)'),
        (Machine: 'ipad4,4'; Name: 'iPad mini Retina (WiFi)'),
        (Machine: 'ipad4,5'; Name: 'iPad mini Retina (GSM+CDMA)'),
        (Machine: 'ipad4,6'; Name: 'iPad mini Retina (China)'),
        (Machine: 'ipad4,7'; Name: 'iPad mini 3 (WiFi)'),
        (Machine: 'ipad4,8'; Name: 'iPad mini 3 (GSM+CDMA)'),
        (Machine: 'ipad4,9'; Name: 'iPad Mini 3 (China)'),
        (Machine: 'ipad5,1'; Name: 'iPad mini 4 (WiFi)'),
        (Machine: 'ipad5,2'; Name: '4th Gen iPad mini (WiFi+Cellular)'),
        (Machine: 'ipad5,3'; Name: 'iPad Air 2 (WiFi)'),
        (Machine: 'ipad5,4'; Name: 'iPad Air 2 (Cellular)'),
        (Machine: 'ipad6,11'; Name: 'iPad (2017)'),
        (Machine: 'ipad6,12'; Name: 'iPad (2017)'),
        (Machine: 'ipad6,3'; Name: 'iPad Pro (9.7 inch, WiFi)'),
        (Machine: 'ipad6,4'; Name: 'iPad Pro (9.7 inch, WiFi+LTE)'),
        (Machine: 'ipad6,7'; Name: 'iPad Pro (12.9 inch, WiFi)'),
        (Machine: 'ipad6,8'; Name: 'iPad Pro (12.9 inch, WiFi+LTE)'),
        (Machine: 'ipad7,1'; Name: 'iPad Pro 2nd Gen (WiFi)'),
        (Machine: 'ipad7,11'; Name: 'iPad 7th Gen 10.2-inch (WiFi)'),
        (Machine: 'ipad7,12'; Name: 'iPad 7th Gen 10.2-inch (WiFi+Cellular)'),
        (Machine: 'ipad7,2'; Name: 'iPad Pro 2nd Gen (WiFi+Cellular)'),
        (Machine: 'ipad7,3'; Name: 'iPad Pro 10.5-inch'),
        (Machine: 'ipad7,4'; Name: 'iPad Pro 10.5-inch'),
        (Machine: 'ipad7,5'; Name: 'iPad 6th Gen (WiFi)'),
        (Machine: 'ipad7,6'; Name: 'iPad 6th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,1'; Name: 'iPad Pro 11 inch 3rd Gen (WiFi)'),
        (Machine: 'ipad8,10'; Name: 'iPad Pro 11 inch 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,11'; Name: 'iPad Pro 12.9 inch 4th Gen (WiFi)'),
        (Machine: 'ipad8,12'; Name: 'iPad Pro 12.9 inch 4th Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,2'; Name: 'iPad Pro 11 inch 3rd Gen (1TB, WiFi)'),
        (Machine: 'ipad8,3'; Name: 'iPad Pro 11 inch 3rd Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,4'; Name: 'iPad Pro 11 inch 3rd Gen (1TB, WiFi+Cellular)'),
        (Machine: 'ipad8,5'; Name: 'iPad Pro 12.9 inch 3rd Gen (WiFi)'),
        (Machine: 'ipad8,6'; Name: 'iPad Pro 12.9 inch 3rd Gen (1TB, WiFi)'),
        (Machine: 'ipad8,7'; Name: 'iPad Pro 12.9 inch 3rd Gen (WiFi+Cellular)'),
        (Machine: 'ipad8,8'; Name: 'iPad Pro 12.9 inch 3rd Gen (1TB, WiFi+Cellular)'),
        (Machine: 'ipad8,9'; Name: 'iPad Pro 11 inch 4th Gen (WiFi)'),
        (Machine: 'iphone1,1'; Name: 'iPhone'),
        (Machine: 'iphone1,2'; Name: 'iPhone 3G'),
        (Machine: 'iphone10,1'; Name: 'iPhone 8'),
        (Machine: 'iphone10,2'; Name: 'iPhone 8 Plus'),
        (Machine: 'iphone10,3'; Name: 'iPhone X Global'),
        (Machine: 'iphone10,4'; Name: 'iPhone 8'),
        (Machine: 'iphone10,5'; Name: 'iPhone 8 Plus'),
        (Machine: 'iphone10,6'; Name: 'iPhone X GSM'),
        (Machine: 'iphone11,2'; Name: 'iPhone XS'),
        (Machine: 'iphone11,4'; Name: 'iPhone XS Max'),
        (Machine: 'iphone11,6'; Name: 'iPhone XS Max Global'),
        (Machine: 'iphone11,8'; Name: 'iPhone XR'),
        (Machine: 'iphone12,1'; Name: 'iPhone 11'),
        (Machine: 'iphone12,3'; Name: 'iPhone 11 Pro'),
        (Machine: 'iphone12,5'; Name: 'iPhone 11 Pro Max'),
        (Machine: 'iphone12,8'; Name: 'iPhone SE 2nd Gen'),
        (Machine: 'iphone13,1'; Name: 'iPhone 12 Mini'),
        (Machine: 'iphone13,2'; Name: 'iPhone 12'),
        (Machine: 'iphone13,3'; Name: 'iPhone 12 Pro'),
        (Machine: 'iphone13,4'; Name: 'iPhone 12 Pro Max'),
        (Machine: 'iphone2,1'; Name: 'iPhone 3GS'),
        (Machine: 'iphone3,1'; Name: 'iPhone 4'),
        (Machine: 'iphone3,2'; Name: 'iPhone 4 GSM Rev A'),
        (Machine: 'iphone3,3'; Name: 'iPhone 4 CDMA'),
        (Machine: 'iphone4,1'; Name: 'iPhone 4S'),
        (Machine: 'iphone5,1'; Name: 'iPhone 5 (GSM)'),
        (Machine: 'iphone5,2'; Name: 'iPhone 5 (GSM+CDMA)'),
        (Machine: 'iphone5,3'; Name: 'iPhone 5C (GSM)'),
        (Machine: 'iphone5,4'; Name: 'iPhone 5C (Global)'),
        (Machine: 'iphone6,1'; Name: 'iPhone 5S (GSM)'),
        (Machine: 'iphone6,2'; Name: 'iPhone 5S (Global)'),
        (Machine: 'iphone7,1'; Name: 'iPhone 6 Plus'),
        (Machine: 'iphone7,2'; Name: 'iPhone 6'),
        (Machine: 'iphone8,1'; Name: 'iPhone 6s'),
        (Machine: 'iphone8,2'; Name: 'iPhone 6s Plus'),
        (Machine: 'iphone8,4'; Name: 'iPhone SE (GSM)'),
        (Machine: 'iphone9,1'; Name: 'iPhone 7'),
        (Machine: 'iphone9,2'; Name: 'iPhone 7 Plus'),
        (Machine: 'iphone9,3'; Name: 'iPhone 7'),
        (Machine: 'iphone9,4'; Name: 'iPhone 7 Plus'),
        (Machine: 'ipod1,1'; Name: '1st Gen iPod'),
        (Machine: 'ipod2,1'; Name: '2nd Gen iPod'),
        (Machine: 'ipod3,1'; Name: '3rd Gen iPod'),
        (Machine: 'ipod4,1'; Name: '4th Gen iPod'),
        (Machine: 'ipod5,1'; Name: '5th Gen iPod'),
        (Machine: 'ipod7,1'; Name: '6th Gen iPod'),
        (Machine: 'ipod9,1'; Name: '7th Gen iPod'),
        (Machine: 'watch1,1'; Name: 'Apple Watch 38mm case'),
        (Machine: 'watch1,2'; Name: 'Apple Watch 42mm case'),
        (Machine: 'watch2,3'; Name: 'Apple Watch Series 2 38mm case'),
        (Machine: 'watch2,4'; Name: 'Apple Watch Series 2 42mm case'),
        (Machine: 'watch2,6'; Name: 'Apple Watch Series 1 38mm case'),
        (Machine: 'watch2,7'; Name: 'Apple Watch Series 1 42mm case'),
        (Machine: 'watch3,1'; Name: 'Apple Watch Series 3 38mm case (GPS+Cellular)'),
        (Machine: 'watch3,2'; Name: 'Apple Watch Series 3 42mm case (GPS+Cellular)'),
        (Machine: 'watch3,3'; Name: 'Apple Watch Series 3 38mm case (GPS)'),
        (Machine: 'watch3,4'; Name: 'Apple Watch Series 3 42mm case (GPS)'),
        (Machine: 'watch4,1'; Name: 'Apple Watch Series 4 40mm case (GPS)'),
        (Machine: 'watch4,2'; Name: 'Apple Watch Series 4 44mm case (GPS)'),
        (Machine: 'watch4,3'; Name: 'Apple Watch Series 4 40mm case (GPS+Cellular)'),
        (Machine: 'watch4,4'; Name: 'Apple Watch Series 4 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,1'; Name: 'Apple Watch Series 5 40mm case (GPS)'),
        (Machine: 'watch5,10'; Name: 'Apple Watch SE 44mm case (GPS)'),
        (Machine: 'watch5,11'; Name: 'Apple Watch SE 40mm case (GPS+Cellular)'),
        (Machine: 'watch5,12'; Name: 'Apple Watch SE 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,2'; Name: 'Apple Watch Series 5 44mm case (GPS)'),
        (Machine: 'watch5,3'; Name: 'Apple Watch Series 5 40mm case (GPS+Cellular)'),
        (Machine: 'watch5,4'; Name: 'Apple Watch Series 5 44mm case (GPS+Cellular)'),
        (Machine: 'watch5,9'; Name: 'Apple Watch SE 40mm case (GPS)'),
        (Machine: 'watch6,1'; Name: 'Apple Watch Series 6 40mm case (GPS)'),
        (Machine: 'watch6,2'; Name: 'Apple Watch Series 6 44mm case (GPS)'),
        (Machine: 'watch6,3'; Name: 'Apple Watch Series 6 40mm case (GPS+Cellular)'),
        (Machine: 'watch6,4'; Name: 'Apple Watch Series 6 44mm case (GPS+Cellular)'),
        (Machine: 'x86_64'; Name: 'iPhone Simulator'));
    var
      LDevice: TAppleDevice;
      LIndex: Integer;
      LStringComparer: IComparer<string>;
    begin
      LDevice.Machine := AMachine.ToLower;
      LDevice.Name := '';
      LStringComparer := TComparer<string>.Default;
      if TArray.BinarySearch<TAppleDevice>(AppleDevices, LDevice, LIndex, TComparer<TAppleDevice>.Construct(
        function(const ALeft, ARight: TAppleDevice): Integer
        begin
          Result := LStringComparer.Compare(ALeft.Machine, ARight.Machine);
        end)) then
      begin
        Result := AppleDevices[LIndex].Name;
      end
      else if AMachine.IsEmpty then
        Result := ''
      else
      begin
        {$IFDEF DEBUG}
        for LIndex := 0 to Length(AppleDevices)-1 do
          if (AppleDevices[LIndex].Machine <> AppleDevices[LIndex].Machine.ToLower) then
            raise Exception.Create('Apple device list is wrong (the "Machine" field don''t allow upper case)');
        for LIndex := 1 to Length(AppleDevices)-1 do
          if LStringComparer.Compare(AppleDevices[LIndex-1].Machine, AppleDevices[LIndex].Machine) <> -1 then
            raise Exception.Create('Apple device list is wrong (it isn''t ordered or have duplicate item)');
        {$ENDIF}
        Result := '[' + AMachine + ']';
      end;
    end;

  var
    LSize: size_t;
    LDeviceModelBuffer: array of Byte;
  begin
    sysctlbyname('hw.machine', nil, @LSize, nil, 0);
    if LSize > 0 then
    begin
      SetLength(LDeviceModelBuffer, LSize);
      sysctlbyname('hw.machine', @LDeviceModelBuffer[0], @LSize, nil, 0);
      Result := GetPrettyName(UTF8ToString(MarshaledAString(LDeviceModelBuffer)));
    end
    else
      Result := '';
  end;

 

This solution works great! Thank you!

But any suggestions for the general "problem" to program a static library in xcode for use in delphi?

 

Thanks!

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×