If your iOS app needs to perform some work while it is running in the background on iOS, you’ll need to do some special “tweaking”, since the functionality is not provided for in the IDE.
When Delphi compiles your iOS app for the selected release type (i.e. either Debug or Release), it creates a file called <appname>.info.plist, where <appname> is the name of your application. This file is deployed to iOS as Info.plist and is the file that iOS uses to determine whether your app uses any background services. The types of background services supported on iOS is described in the Apple iOS documentation here, however to summarize, they are:
||The app plays audible content to the user or records audio while in the background. (This content includes streaming audio or video content using AirPlay.)|
||The app keeps users informed of their location, even while it is running in the background.|
|Voice over IP||
||The app provides the ability for the user to make phone calls using an Internet connection.|
||The app is a Newsstand app that downloads and processes magazine or newspaper content in the background.|
|External accessory communication||
||The app works with a hardware accessory that needs to deliver updates on a regular schedule through the External Accessory framework.|
||The app works with a Bluetooth accessory that needs to deliver updates on a regular schedule through the Core Bluetooth framework.|
|Bluetooth data sharing||
||The app supports Bluetooth communication in peripheral mode through the Core Bluetooth framework.Using this mode requires user authorization; for more information, see “Best Practices for Maintaining User Privacy.”|
||The app regularly downloads and processes small amounts of content from the network.|
||The app’s response to a push notification includes optionally downloading content related to the notification. The purpose of downloading the content in the background is to incorporate it and be able to present it immediately when the user responds to the push notification.|
In order for your app to support background processing for any or all of these services, you’ll need to create a copy of the <appname>.info.plist file (note: you’ll need to compile at least once in order for the IDE to create the file) and manually edit it, because Delphi overwrites the original file every time you compile your app. The file also contains other information that will change if you change certain project options, so you’ll need to keep that in mind so that you can re-insert the background services information.
Once you’ve copied the <appname>.info.plist file (it makes sense to have it in the same directory, or even in the project root directory), you can edit the file with a “unix-eol-friendly” editor such as Notepad++, and anywhere inside the <dict> tag, add the following (I usually place it just before the end </dict> tag), for example:
<key>UIBackgroundModes</key> <array> <string>location</string> </array>
You’ll need to add a separate <string> key for each service your app will support. In the Delphi deployment manager (click Project|Deployment in the main menu), uncheck the original <appname>.info.plist:
then click the little yellow “Add Files” button at the top left of the Deployment window, select the file you copied and edited earlier and click Open. For the file you just added, click the name of the file in the Remote Name column, click it again to put it into edit mode:
and rename it to Info.plist. (make sure it has a capital “I” at the beginning). Make sure you save these changes.
Now when Delphi deploys your app, the new Info.plist file will be deployed along with it. Once again, remember that if you make changes to some project options, such as the icons, or the version info, you may need to go through this process again, since those changes will be in the original <appname>.info.plist file. Perhaps in the near future someone might come up with an expert to manage this automatically.