Show: Object Pascal C++
Display Preferences

Creating an iOS App

From Appmethod Topics
Jump to: navigation, search

Go Up to FireMonkey Applications Guide

Go Up to iOS Mobile Application Development


To create your iOS app:

File > New > FireMonkey Mobile Application - Object Pascal
File > New > FireMonkey Mobile Application - C++

iOS Forms

Using the FireMonkey Mobile Form, you can add additional forms the same way you do with desktop applications.

The iOS form has specific hardware-dependent properties. For example, the iOS form has a different shape or footprint than a standard desktop FireMonkey form, as follows:

  • For a FireMonkey iOS application, the form is a vertical shape:
    • ClientHeight = 480 pixels
    • ClientWidth = 320 pixels
  • For a FireMonkey desktop application, the form is a horizontal shape:
    • ClientHeight = 480 pixels
    • ClientWidth = 600 pixels

Releasing Forms in iOS Apps

In general, mobile applications should not keep many forms in memory at once. Mobile devices are memory constrained, and forms are memory intensive objects.

A recommended strategy is to show a form, and when it is no longer visible, release the form (either by using the OnClose event handler and setting the CloseEvent to caFree, or by calling the System.TObject.DisposeOf method of the form).

Using a tab control with multiple pages can be a more memory-efficient mechanism for displaying multiple form-like controls.

FireMonkey iOS Workflow

At different times during the FireMonkey iOS development process, you need to work either on your development platform or on the Mac. After you complete the required setup steps and compile your project in the Appmethod IDE, running your project will transfer the executable and necessary libraries to the Mac.

Important: Start Here

  • Before starting your first iOS project, you must perform several important installation and setup steps on both Windows and the Mac. For example, you need to provide a Development Provisioning Profile for any specific iOS development devices you want to use in testing your application on the Mac.

Then develop your project in the following general sequence:

Steps in Appmethod

  1. Start your project using either of the FireMonkey iOS wizards:
    File > New > Other > Object Pascal Projects > FireMonkey Mobile Application
    File > New > Other > C++ Projects > FireMonkey Mobile Application
  2. Select one of the templates and applications that are presented, such as Tabbed, or Blank Application.
  3. The iOS Form is displayed in the Form Designer.
    Use the Form Designer and Code Editor in Appmethod to add controls to the form, to set values for properties and events, and to write the code behind.
Tip: Start creating your iOS app by working through the Mobile Tutorials: Mobile Application Development (iOS and Android).

Steps on the Mac and on the iOS Simulator or an Attached iOS Device

  1. For prototyping purposes, run or debug your project using the iOS Simulator target platform.
    • Tip: Run your application on the iOS Simulator at least once after creating the project (and whenever you make changes or add new files to the project).
  2. Select the device that is to run your app, such as:
    • The built-in iOS Simulator for initial debugging purposes.
    • A physical iOS device, connected to the Mac.

To run your iOS app on an iOS device:

  • Your iOS device must be connected to the Mac by USB cable.
  • You need to add a new SDK from the SDK Manager page. After you add the new SDK, your selected version of the iOS SDK is pulled from the Mac to your development system.
  • You must create a Development Provisioning Profile for testing your application on your development iOS device.
    The Provisioning Profile associates your Apple Developer ID with:
    • Specific iOS apps you want to run (identified by App ID)
    • The specific iOS devices where you want to run the apps (identified by the device ID or UDID)
      You can find the 40-character UDID through Xcode or iTunes. For more information, see https://developer.apple.com/ios/manage/devices/howto.action

For more information about the workflow for iOS apps on the Mac, see https://developer.apple.com/library/IOs/referencelibrary/GettingStarted/RoadMapiOS/index.html.

Preferred Components for iOS Apps vs. Desktop Applications

On the iOS platform, the native style and format is distinct from the style and format of desktop applications. That is, your iOS app should observe iOS-specific rules about formatting and placement of components.

For example, here is a list that compares FireMonkey components typically used in desktop apps with components that are preferred for iOS apps:

Key Component Differences:

Desktop Components iOS Components

TTreeView

TListView
TListBox

TRadioGroup
TRadioButton

TSegmentedControl
ListBox

TCheckBox

TSwitch

TMenuBar
TMainMenu

TToolBar with buttons
TTabControl


Preferred FireMonkey Components for iOS Apps:

TButton TEdit TCalendarEdit TListView
TTrackBar TTabControl TSpeeButton TMemo
TSwitch TComboBox TToolBar TScrollBox
TLabel TNumberBox TListBox TProgressBar
TPanel

For further information, in both PDF and video format (including specific recommendations for format and style), see the EDN article iOS User Interface Design with Object Pascal XE4.

For example, the EDN article contains tips for using common components such as TListBox, TListView, TToolBar, and TSpeedButton in your iOS apps, plus a detailed demo that shows you how to create a Settings app on the iOS platform:

Sample Individual Frames from iOS User Interface Design with Object Pascal XE4

ListBoxRules.png
  TListBox Rules

ListViewRules.png
  TListView Rules

SettingsDemo.png
  Settings Demo


Component Restrictions for FireMonkey iOS Apps

While you are designing your iOS app in Appmethod, you can only use components that are supported on iOS devices. However, be aware that the Tool Palette might contain some components that are Windows-only or are otherwise not supported on iOS.

International (Unicode) Characters Not Accepted on iOS Target Platform

International (Unicode) characters are not accepted in several places in an iOS app. For example, names such as hélène and éléments can prevent the iOS app from running.

Specifically, do not use international characters in:

  • Your Windows user name
  • A connection profile name
  • Your iOS project name
  • The name of the application bundle (the .app executable)

The following message appears when you try to build an iOS app that contains Unicode characters:

  Can't get full path to application bundle. No such file or directory

In this case, the iOS app is generated in the PAServer scratch-dir, but it does not run on either the iOS Device or the iOS Simulator.

Additionally, when using C++ to create an iOS application, do not use System::UnicodeString mixed with std::wstring. The reason behind this is that std::wstring uses 4-byte characters (wchar_t), while System::UnicodeString uses 2-byte characters (char16_t).

Using Frameworks in iOS Apps

RTL

Some RTL units that provide basic functionality are common for all platforms, such as System.pas or System.SysUtils.pas.

A number of RTL units are iOS-only (see iOS Objective-C Frameworks). These units are prefixed with the iOSapi unit scope.

See also iOS C RTL.

FireMonkey

The FireMonkey framework is ideal for the iOS target platform, and it also supports Mac OS X and both Win32 and Win64. See FireMonkey Platform Prerequisites.


iOS Objective-C Frameworks (iOSapi)

The RTL contains a number of units that provide Object Pascal and C++ interfaces to iOS frameworks written in Objective-C. These units are scoped with iOSapi and are typically located in the /source/rtl directory of your product installation:

  • iOSapi.AssetsLibrary
  • iOSapi.AVFoundation
  • iOSapi.CocoaTypes
  • iOSapi.CoreAudio
  • iOSapi.CoreData
  • iOSapi.CoreGraphics
  • iOSapi.CoreImage
  • iOSapi.CoreLocation
  • iOSapi.CoreMedia
  • iOSapi.CoreMotion
  • iOSapi.CoreTelephony
  • iOSapi.CoreText
  • iOSapi.CoreVideo
  • iOSapi.Foundation
  • iOSapi.GLKit
  • iOSapi.MediaPlayer
  • iOSapi.OpenGLES
  • iOSapi.QuartzCore
  • iOSapi.UIKit

The FireMonkey framework relies on some of these units.

Documentation for iOS Libraries

For help on these APIs, see the Apple documentation at iOS Developer Library. Appmethod does not provide help for the libraries you might need to use on the Mac.

You can also register as an iOS developer (free of charge) at the iOS Dev Center. Being a registered member of the iOS Developer Program enables you to distribute apps in the App Store (this is along with other requirements, such as a developer certificate and a provisioning profile). For more information, see http://developer.apple.com/programs/ios/gettingstarted/

OpenSSL Support

Appmethod uses OpenSSL for HTTPS support in Indy, Amazon and Azure cloud services, and in DataSnap clients when encryption filters are enabled or when the Communication Protocol is set to HTTPS in the DataSnap Server Wizard.

If your iOS application requires OpenSSL support, you must configure your project to include the required libraries: libcrypto and libssl.

  • For the iOS Device target platform, which does not support dynamic libraries, you need a static version of these library files (libcrypto.a and libssl.a). To obtain these library files, do either of the following:
    After you have these library files, copy them into a folder where your project searches for libraries, such as the main project folder.
  • For the iOS Simulator target platform, which does support dynamic libraries, do either of the following:
    • Use Indy's IdOpenSSLSetLibPath() to set the path to the location on the Mac where the library files (libcrypto.dylib and libssl.dylib) are located.
      Note: Letting the Mac find the OpenSSL libraries on its own might not work for the iOS Simulator target platform, as you might have an unsupported version of the OpenSSL library files in the library folders that the simulator uses.
    • Copy the iOS simulator OpenSSL library files from the Mac into your project source folder, and deploy them to the simulator along with your application.

In order to have a working application that uses the OpenSSL library (for example, if your app connects to a service provider through HTTPS such as Amazon, Azure, or DataSnap), you need to add the IdSSLOpenSSLHeaders_static unit to any uses clause of your project.

When you create a C++ iOS application, after you obtain the required libraries, you must configure your project to link with them. Select Project > Options > C++ Linker, and set "Link with SSL and Crypto" to True.

Loading and Deploying Files

When you deploy your application for the iOS Device target platform, if you plan to provide files along with your application to load those files at run time, use the Deployment Manager to place those files in the StartUp\Documents folder during deployment.

ChangeToStartUpDocuments.png

Use the following code to locate those files at run time:

In Object Pascal:

TPath.Combine(TPath.GetDocumentsPath, 'filename')

In C++:

System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetDocumentsPath(), L"filename")

Here filename is the name of your file, such as 'dbdemos.gdb' in the screenshot above. The TPath record is declared in the System.IOUtils unit, so you need to add System.IOUtils in the uses clause.

Writing Code for iOS Only

You can use conditional compilation to write code that only builds when the target platform is iOS.

In Object Pascal you can use the following predefined conditionals:

{$IF Defined(IOS) }
// Code for both iOS Device and iOS Simulator.
{$ENDIF}
 
{$IF Defined(IOS) and Defined(CPUARM) }
// Code for iOS Device only.
{$ENDIF}
 
{$IF Defined(IOS) and Defined(CPUX86) }
// Code for iOS Simulator only.
{$ENDIF}

In C++, Apple recommends using the definition TARGET_OS_IPHONE, which is defined if you include the TargetConditionals.h header. If you include "System.hpp", "TargetConditionals.h" is included as well. In this case, you can use:

#if defined(TARGET_OS_IPHONE)
// Code for iOS Device.
#endif

Alternatively, you can use definitions to detect the BCCIOSARM compiler.

Implementing iOS-specific Features

The following topics describe how to implement some iOS-specific features in your applications:

Find documentation about other, platform-agnostic features in the FireMonkey Applications Guide.

See Also

Personal tools
In other languages