iOS Services

1. How to use iOS services

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="GameInitialize">
  <ios>
    <services>
      <service name="apple_game_center" />
    </services>
  </ios>
</project>

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

Note

If you have installed the pod command using above instructions, and executing the pod --version in terminal works for you OK, but the CGE editor says that it "Cannot find pod command", then try a workaround: execute the editor from the command-line. Type in the terminal <location-where-you-downloaded-engine>/castle_game_engine/bin/castle-editor.app/Contents/MacOS/castle-editor and press <Enter>. Try to build iOS application from that editor.

The more long-term solution would be to add the path to pod to CGE GUI application, but it’s not as straightforward on various macOS versions (see pointers here).

4. Adding new services

Adding new iOS service is deliberately very consistent with creating new service for Android, which is documented on Adding New Android Services.

  • In case of iOS you write code using Objective-C.

  • Similarly to Android, we have a base class in Objective-C ServiceAbstract with methods you can override, that correspond to typical iOS application lifecycle.

  • See existing service code build-tool/data/ios/services for examples.

  • Same as on Android, you can use CastleMessaging to communicate with Pascal code asynchronously.

  • On iOS, use static libraries libxxx.a (instead of dynamic libxxx.so).

  • Note that CocoaPods has a lot of common libraries available. You can trivially use Podfile inside a service to reference any library from CocoaPods. See e.g. freetype service on iOS for an example.


To improve this documentation just edit this page and create a pull request to cge-www repository.