iOS Services

Michalis Kamburelis edited this page Jan 10, 2018 · 23 revisions

Table of Contents

How to use iOS services in Castle Game Engine projects

Inside the CastleEngineManifest.xml you can declare which additional services you want to integrate with your iOS application. It looks like this:

<?xml version="1.0" encoding="utf-8"?>
<project name="castle_spine" game_units="Game">
  <ios>
    <services>
      <service name="apple_game_center" />
    </services>
  </ios>
</project>

Currently supported services:

apple_game_center

Integration with the Apple Game Center.

To use this, you will need to configure your application integration with Game Center on the Apple websites:

Then from your Pascal code, you can use TGameService class from the CastleGameService unit to send achievements and more using the Apple Game Center. See the examples/2d_dragon_spine_game/ example, in particular the Game.pas unit source code.

Savegames in the cloud work too. Use simple methods TGameService.SaveGameSave, TGameService.SaveGameLoad from Pascal code. Notes:

  • User must be logged into the iCloud, and have iCloud Drive enabled, see Apple documentation.

  • You must enable iCloud for your App ID in your https://developer.apple.com/ account.

  • You need to use an additional service icloud_for_save_games. In effect, in the application settings in Xcode, you should see that the iCloud is active, with iCloud Documents selected. Like on the screenshot below. (You should not need to adjust them, the generated Xcode project should be already correct. The screenshot is only to allow you to make sure.)

    Xcode iCloud Settings for Apple Game Center with savegames

facebook

Integration with Facebook SDK for iOS. Right now this integration:

  • Notifies Facebook when users run your application on iOS. This may be useful to see installation statistics inside Facebook analytics.
  • The Facebook SDK may also log in-app purchases done by users, if you set appropriate option in the Facebook application config.
  • In Pascal, right now you can only call TFacebook.LoginButton (use CastleFacebook unit) to show the Facebook login button. Users can click it to login/logout from the Facebook application. It does not serve much purpose now except checking that the integration actually works (e.g. you pointed to the correct Facebook app).

When adding this to the CastleEngineManifest.xml, set also parameters describing application id and name for Facebook:

<service name="facebook">
  <parameter key="app_id" value="11223344" />
  <parameter key="app_title" value="My Application Name" />
</service>

To use this:

game_analytics

Integration with the Game Analytics.

From you game Pascal code, use TAnalytics class in the CastleAnalytics unit. Initialize them with InitializeGameAnalytics method and send events to the analytics service using various methods like Event. Also, all the purchases done using in_app_purchases service are automatically send to analytics, with correct price and currency.

Note that you can have both Game Analytics and Google Analytics initialized at the same time. We will send all events to both of them.

This service uses CocoaPods, so make sure you have CocoaPods installed.

google_analytics

Integration with the Google Analytics.

From you game Pascal code, use TAnalytics class in the CastleAnalytics unit. Initialize them with InitializeGoogleAnalytics method and send events to the analytics service using various methods like Event. Also, all the purchases done using in_app_purchases service are automatically send to analytics, with correct price and currency.

Note that you can have both Game Analytics and Google Analytics initialized at the same time. We will send all events to both of them.

This service uses CocoaPods, so make sure you have CocoaPods installed.

Note: You need to create a new "property" in Google Analytics for tracking your mobile application, and obtain a "tracking ID" (like UA-xxx). However, since Google now advices using Firebase for tracking mobile applications, if you click on "Mobile" when creating a new Google Analytics property, it will suggest you to connect your application to Firebase. Instead, create a "Website" property in "Google Analytics" to get a normal tracking ID, and then change the "view" to see mobile application data. See:

icloud_for_save_games

This service enhances the apple_game_center service to be able to store savegames in the cloud. See the apple_game_center documentation above.

in_app_purchases

Allows to sell products within the iOS application, through the Apple AppStore.

In your game, use the TInAppPurchases class from the CastleInAppPurchases unit to communicate with the AppStore, requesting information about the products, purchasing etc.

You need (paid) Apple developer account to use this. And you will need to sign some legal forms to enable in-app purchases. See the Apple documentation for all the details. And you will need to configure the products that can be purchased on the Apple iTunes Connect website.

Be sure to check that the capability "In-App Purchase" is also Enabled for given App ID, in your Apple Developer Account.

ogg_vorbis

This integrates your project with Tremolo to allow loading and playing OggVorbis music on iOS.

This service is automatically added to your project if it has a dependency on OggVorbis, which in turn is automatic if your game data includes some .ogg file. So there's seldom a need to request this service explicitly.

photo_service

Integration with PhotoLibrary.

Use the Pascal class TPhotoService (use CastlePhotoService unit) to store your image into the system Photos app.

Common notes for services using CocoaPods

Some of the services use CocoaPods for installing 3rd-party dependencies easily (e.g. Game Analytics or Google Analytics or Facebook SDK libraries).

In order to use such sevices:

  1. You need to have CocoaPods installed on your system. Just execute sudo gem install cocoapods in the terminal, it should make the pod command available on your $PATH.

    The build tool will internally use pod to download and install service dependencies. This happens completely automatically. If you never used CocoaPods before, be aware that the 1st run may take a while (even a couple of minutes) as a large CocoaPods repository is downloaded.

  2. You should no longer open the project using my_project_name.xcodeproj file. This will not work, as the libPods... library will not be built in this case. Instead, open and run in Xcode the my_project_name.xcworkspace file (it is in the same directory as my_project_name.xcodeproj). Using this will correctly build and run the project with dependencies.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.