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 > Multi-Device Application - Object Pascal
File > New > Multi-Device Application - C++

Then select a multi-device application type in the Multi-Device Application wizard.

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 Multi-Device Application wizards:
    File > New > Other > Object Pascal Projects > Multi-Device Application
    File > New > Other > C++ Projects > Multi-Device Application
  2. Select a multi-device application type in the Multi-Device Application wizard, such as Tabbed, or Blank Application.
  3. The Master Form is displayed in the Form Designer.
  4. Select the iOS target platform to see all the available components for iOS, otherwise they appear grayed out.
    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).

Style Selector

At the top of the multi-device Form Designer is the style selector: StylesFormDes.png

The style selector's drop-down menu lists all the styles that you can apply to the Master view.

Select the iOS style from the style selector to see all the properties on the components according to the target platform.

View Selector

At the top of the multi-device Form Designer is the view selector: ViewsFormDes.png

The view selector's drop-down menu lists all the available views, which show the different platforms, such as iOS, Android, Windows and OS X.

Use the Master Form for the general design of your application. Then you can add new views to your project in order to customize your application for a specific device type. You can even create new customized views; see Adding a Customized View to the View Selector. The standard iOS device views are:

  • iPhone 3.5"
  • iPhone 4"
  • iPad Mini
  • iPad

All the views inherit the components and properties from the Master form. For more information, see Form Designer.

Note: If you want to customize some aspects of your application for all iOS devices, you can do this using the Master form, provided you do not want to propagate to the rest of platforms. Otherwise, use the Code Editor, for example:
// You will see the changes applied at run time.
{$IFDEF IOS} 
    SpeedButton1.StyleLookup := priortoolbutton; 
{$ENDIF}

For more information:

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.

Equivalence between Views and iOS Simulator Targets

View iOS Simulator Target

IPad Mini

iPad

iPhone 3.5

iPhone

iPhone 4

iPhone5

Requirements for Running Your iOS App on an iOS Device

See more info: iOS Mobile Application Development
  • 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:

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 vs. Desktop Platforms

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

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

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. When iOS is the active target platform of your project, unsupported components are grayed out on the Tool Palette.

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).

Releasing Forms in iOS Apps

In general, multi-device 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.

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.

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), 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