C++ Builder Multi-Device application provides three levels of development:

⦁ Components (VCL and FMX)
⦁ Common Libraries (RTL).
⦁ Platform APIs (iOS, Android, Mac OS)

In this post we will discuss and show how to use the Platform APIs (iOS, Android, Mac OS).

Specifically, we’ll look at how to use the iOS APIs to obtain Apple iOS device information for the Operating System (OS) version, the OS name and the iOS device type.

Some refer to this as being able to ‘Touch the Metal’ of the device, meaning having access to the low level APIs of the device.

The C++ Builder Run Time Library (RTL) includes a number of header files that provide C++ interfaces to the iOS frameworks written in Objective-C.

And C++ Builder has the same for Android for the Java Libraries for Android, to allow you to access the APIs of the Android Java libraries from your native C++ code.

For Apple IOS, using C++ Builder, these units are scoped with iOSapi and are installed by default in your installation folder \include\ios\rtl.  For Example:

C++ Builder Multi-Device application example

The complete list of these units are listed on this C++ Builder DocWiki page iOS Objective-C Frameworks (iOSapi)

The C++ Builder FireMonkey framework relies on some of these units.

For help on these iOS APIs, you can see the Apple documentation at iOS Developer Library

To get to the iOS device information we need, we will need to use the iOS Objective-C Framework for:  iOSapi.UIKit.hpp

Note:  The iOSapi.UIKit.hpp also includes the iOSapi.Foundation.hpp and the Macapi.Helpers (Macapi.ObjectiveC.hpp):

123#define Iosapi_UikitHPP#include <iOSapi.Foundation.hpp>#include <Macapi.ObjectiveC.hpp>

Here are steps to create a C++ Builder Multi-Device application to display Apple iOS device information for the Operating System (OS) version, the OS name and the iOS device type:

  1. Create a new C++ Builder Multi-Device applicationBLANK. Target Platform = iOS 64-bit.
  2. Save Project in a new Folder, such as /Projects/CppiOSDeviceInfo
  3. Use Project | Options | Deployment | Provisioning, to select your Apple Provisioning Profile and your Developer Certificate:
How ro implement C++ Builder Multi-Device application in Your next software  project

4. Use Project | Options | Application | Version Info | to enter your unique Application Identifier for the CFBundleIdentifierQ4X27M46Z4.$(ModuleName)

5. In our C++ Builder Multi-Device iOS application, we will include this one header file:  #include <iOSapi.UIKit.hpp>

1234#include <fmx.h>#include <iOSapi.UIkit.hpp>  // iOS Device information#pragma hdrstop#include “uMain.h”

6. For the User Interface (UI), create a UI that look like this:

7. To create this UI, follow these steps:

On your Blank form in your new C++ Builder Multi-Device application:

a. Add a Toolbar, property Align = Top.

b. On the Toolbar, add a ButtonAlign = RightButton Name = btnGetDeviceInfoStyleLookup = refreshtoolbuttonbordered.

c. On the Toolbar, add a Label, Align = Contents. Label->Text = Device Information

d. To display the iOS Device information we will use a ListBox. Add ListBox to the form. Align = Top.

e. To the ListBox, add three (3) ListBoxItems, to display the OS version, the OS name and the iOS device type.  To do this, in the Structure Pane, Right-click on ListBox1, Items Editor, Select ListBoxItem from the dropdown, Click Add item button 3 times. Rename ListBoxItem’s TEXT values as OS Name:, Device Type:, and OS Version, and ListBoxItem.Name = lbOSName , lbDeviceType, and lbOSVersion , respectively.

8. You can now double-click on the button for GetDeviceInfo and for it’s OnClick Event Handler, and you can use the functions and methods in the iOSapi UIKit header file to get OS information from our iOS device.

9. First, in your C++ Builder IDE, lets look at the iOSapi.UIKit.hpp header file.  In the IDE Editor, select the iOSapi.UIKit.hpp | Right-Click | Open File At Cursor.  This should open the iOSapi.UIKit.hpp header file in the Editor.

10. Looking at the “Methods Insite” dropdown, we see all the iOS UI kit APIs available for us to use. For our application, we are needing Device information, so typing Device in the “Methods Insite” box, shows us the methods we can use. For example, we see we have UIDeviceClass.currentDevice, plus other UIDevice methods for us to use:

C++ Builder Multi-Device application for any software applications in Romania

11. For our Button Click Get Device Info, we can use this code:

123void __fastcall TForm2::btnGetDeviceInfoClick(TObject *Sender){ _di_UIDevice device

12. To see where this interface _di_UIDevice comes from in the iOSApi header file, Right-click on _di_UIDevice and Find Declaration (you see it’s an interface from the iOSApi.UIKit.hpp header file on line 310):

12typedef System::DelphiInterface<UIDevice> _di_UIDevice;class DELPHICLASS TUIDevice;

13. So now we can use iOS’s own UIDevice class (TUIDevice) we can get the currentDevice by doing a Wrap to the TUIDevice, like this:

123void __fastcall TForm2::btnGetDeviceInfoClick(TObject *Sender){ _di_UIDevice device = TUIDevice::Wrap(TUIDevice::OCClass->currentDevice());

14. Now, to get the OS Name, we can call the device->systemName()

1lbOSName->Text = lbOSName->Text.sprintf(L”OS Name: %s”, device->systemName()->UTF8String());

15. And we can do the same to get the Device’s OS Version, by calling device->systemVersion()

1lbOSVersion->Text = lbOSVersion->Text.sprintf(L”OS Version: %s”, device->systemVersion()->UTF8String());

16. And we can get the Device’s Type, by calling device->model()

1lbDeviceType->Text = lbDeviceType->Text.sprintf(L”Device Type: %s”, device->model()->UTF8String());

17. Deploy and run the app on an iOS 64-bit iPad Air 2 shows this device information:

18.  Source code for this C++ Builder 10.4.1 Sydney application is here