Skip to content

Commit 63cb6a1

Browse files
authored
Merge pull request #4693 from naithar/ios-plugins
Update iOS plugins documentation
2 parents f0b19b4 + 89fd7ef commit 63cb6a1

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

tutorials/export/exporting_for_ios.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ you will be able to continue to edit your Godot project in its current location.
9393
That's it! You can now edit your project in the Godot editor and build it
9494
in Xcode when you want to run it on a device.
9595

96-
Services for iOS
97-
----------------
96+
Plugins for iOS
97+
---------------
9898

99-
Special iOS services can be used in Godot. Check out the
100-
:ref:`doc_services_for_ios` page.
99+
Special iOS plugins can be used in Godot. Check out the
100+
:ref:`doc_plugins_for_ios` page.

tutorials/platform/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ Platform-specific
77

88
android/index
99
ios/index
10-
services_for_ios
1110
platform_html5
1211
consoles

tutorials/platform/ios/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ iOS plugins
66
:name: toc-tutorials-plugins-ios
77

88
ios_plugin
9+
plugins_for_ios

tutorials/platform/ios/ios_plugin.rst

+18-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ iOS plugins allow you to use third-party libraries and support iOS-specific feat
1010
Loading and using an existing plugin
1111
------------------------------------
1212

13-
An iOS plugin requires a ``.gdip`` configuration file, a ``.a`` binary file, and possibly other dependencies. To use it, you need to:
13+
An iOS plugin requires a ``.gdip`` configuration file, a binary file which can be either ``.a`` static library or ``.xcframework`` containing ``.a`` static libraries, and possibly other dependencies. To use it, you need to:
1414

1515
1. Copy the plugin's files to your Godot project's ``res://ios/plugins`` directory. You can also group files in a sub-directory, like ``res://ios/plugins/my_plugin``.
1616

@@ -29,7 +29,7 @@ When a plugin is active, you can access it in your using ``Engine.get_singleton(
2929
Creating an iOS plugin
3030
----------------------
3131

32-
At its core, a Godot iOS plugin is an iOS static library (*.a* archive file) with the following requirements:
32+
At its core, a Godot iOS plugin is an iOS library (*.a* archive file or *.xcframework* containing static libraries) with the following requirements:
3333

3434
- The library must have a dependency on the Godot engine headers.
3535

@@ -39,7 +39,9 @@ An iOS plugin can have the same functionality as a Godot module but provides mor
3939

4040
Here are the steps to get a plugin's development started. We recommend using `Xcode <https://developer.apple.com/develop/>`_ as your development environment.
4141

42-
.. seealso:: The `Godot iOS plugin template <https://github.com/naithar/godot_ios_plugin>`_ gives you all the boilerplate you need to get your iOS plugin started.
42+
.. seealso:: The `Godot iOS Plugins <https://github.com/godotengine/godot-ios-plugins>`_ Godot iOS plugins.
43+
44+
The `Godot iOS plugin template <https://github.com/naithar/godot_ios_plugin>`_ gives you all the boilerplate you need to get your iOS plugin started.
4345

4446

4547
To build an iOS plugin:
@@ -56,9 +58,11 @@ To build an iOS plugin:
5658

5759
3. In the ``Build Settings`` tab, specify the compilation flags for your static library in ``OTHER_CFLAGS``. The most important ones are ``-fcxx-modules``, ``-fmodules``, and ``-DDEBUG`` if you need debug support. Other flags should be the same you use to compile Godot. For instance, ``-DPTRCALL_ENABLED -DDEBUG_ENABLED, -DDEBUG_MEMORY_ALLOC -DDISABLE_FORCED_INLINE -DTYPED_METHOD_BIND``.
5860

59-
4. Add the required logic for your plugin and build your library to generate a ``.a`` file. You will probably need to build both ``debug`` and ``release`` targeted ``a`` files. Depending on your need, pick only one or both. If you need both ``a`` files their name should match following pattern: ``[PluginName].[TargetType].a``. You can also build the static library with your SCons configuration.
61+
4. Add the required logic for your plugin and build your library to generate a ``.a`` file. You will probably need to build both ``debug`` and ``release`` target ``.a`` files. Depending on your needs, pick either or both. If you need both debug and release ``.a`` files, their name should match following pattern: ``[PluginName].[TargetType].a``. You can also build the static library with your SCons configuration.
62+
63+
5. The iOS plugin system also supports ``.xcframework`` files. To generate one, you can use a command such as: ``xcodebuild -create-xcframework -library [DeviceLibrary].a -library [SimulatorLibrary].a -output [PluginName].xcframework``.
6064

61-
5. Create a Godot iOS Plugin configuration file to help the system detect and load your plugin:
65+
6. Create a Godot iOS Plugin configuration file to help the system detect and load your plugin:
6266

6367
- The configuration file extension must be ``gdip`` (e.g.: ``MyPlugin.gdip``).
6468

@@ -80,18 +84,21 @@ To build an iOS plugin:
8084

8185
files=["data.json"]
8286

87+
linker_flags=["-ObjC"]
88+
8389
[plist]
8490
PlistKey="Some Info.plist key you might need"
8591

8692
The ``config`` section and fields are required and defined as follow:
8793

8894
- **name**: name of the plugin
8995

90-
- **binary**: this should be the filepath of the plugin ``a`` file.
96+
- **binary**: this should be the filepath of the plugin library (``a`` or ``xcframework``) file.
9197

92-
- The filepath can be relative (e.g.: ``MyPlugin.a``) in which case it's relative to the directory where ``gdip`` file is located.
93-
- The filepath can be absolute: ``res://some_path/MyPlugin.aar``.
94-
- In case you need multitarget library usage, filename should be ``MyPlugin.a`` and ``a`` files should be name as ``MyPlugin.release.a`` and ``MyPlugin.debug.a``.
98+
- The filepath can be relative (e.g.: ``MyPlugin.a``, ``MyPlugin.xcframework``) in which case it's relative to the directory where the ``gdip`` file is located.
99+
- The filepath can be absolute: ``res://some_path/MyPlugin.a`` or ``res://some_path/MyPlugin.xcframework``.
100+
- In case you need multitarget library usage, the filename should be ``MyPlugin.a`` and ``.a`` files should be named as ``MyPlugin.release.a`` and ``MyPlugin.debug.a``.
101+
- In case you use multitarget ``xcframework`` libraries, their filename in the configuration should be ``MyPlugin.xcframework``. The ``.xcframework`` files should be named as ``MyPlugin.release.xcframework`` and ``MyPlugin.debug.xcframework``.
95102

96103
The ``dependencies`` and ``plist`` sections are optional and defined as follow:
97104

@@ -107,4 +114,6 @@ To build an iOS plugin:
107114

108115
- **files**: contains a list of files that should be copied on export. This is useful for data files or images.
109116

117+
- **linker_flags**: contains a list of linker flags to add to the Xcode project when exporting the plugin.
118+
110119
- **plist**: should have keys and values that should be present in ``Info.plist`` file following pattern: ``KeyName="key value"``

tutorials/platform/services_for_ios.rst renamed to tutorials/platform/ios/plugins_for_ios.rst

+35-45
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
.. _doc_services_for_ios:
1+
.. _doc_plugins_for_ios:
22

3-
Services for iOS
4-
================
3+
Plugins for iOS
4+
===============
55

6-
At the moment, there are two iOS APIs partially implemented, GameCenter
7-
and Storekit. Both use the same model of asynchronous calls explained
8-
below.
6+
At the moment Godot provides StoreKit, GameCenter, iCloud services plugins.
7+
They are using same model of asynchronous calls explained below.
8+
9+
ARKit and Camera access are also provided as plugins.
10+
11+
Accessing plugin singletons
12+
---------------------------
13+
14+
To access plugin functionality, you first need to check that the plugin is
15+
exported and available by calling the `Engine.has_singleton()` function, which
16+
returns a registered singleton.
17+
18+
Here's an example of how to do this in GDScript:
19+
20+
::
21+
22+
var in_app_store
23+
24+
func _ready():
25+
if Engine.has_singleton("InAppStore"):
26+
in_app_store = Engine.get_singleton("InAppStore")
27+
28+
else:
29+
print("iOS IAP plugin is not exported.")
930

1031
Asynchronous methods
1132
--------------------
@@ -28,16 +49,16 @@ the 'pending events' queue. Example:
2849
::
2950

3051
func on_purchase_pressed():
31-
var result = InAppStore.purchase({ "product_id": "my_product" })
52+
var result = in_app_store.purchase({ "product_id": "my_product" })
3253
if result == OK:
3354
animation.play("busy") # show the "waiting for response" animation
3455
else:
3556
show_error()
3657

3758
# put this on a 1 second timer or something
3859
func check_events():
39-
while InAppStore.get_pending_event_count() > 0:
40-
var event = InAppStore.pop_pending_event()
60+
while in_app_store.get_pending_event_count() > 0:
61+
var event = in_app_store.pop_pending_event()
4162
if event.type == "purchase":
4263
if event.result == "ok":
4364
show_success(event.product_id)
@@ -61,10 +82,10 @@ The pending event interface consists of two methods:
6182
Store Kit
6283
---------
6384

64-
Implemented in ``platform/iphone/in_app_store.mm``.
85+
Implemented in `Godot iOS InAppStore plugin <https://github.com/godotengine/godot-ios-plugins/blob/master/plugins/inappstore/in_app_store.mm>`_.
6586

66-
The Store Kit API is accessible through the ``InAppStore`` singleton (will
67-
always be available from GDScript on iOS). It is initialized automatically.
87+
The Store Kit API is accessible through the ``InAppStore`` singleton.
88+
It is initialized automatically.
6889

6990
The following methods are available and documented below:
7091

@@ -213,9 +234,9 @@ finalize the purchase on. Example:
213234
Game Center
214235
-----------
215236

216-
Implemented in ``platform/iphone/game_center.mm``.
237+
Implemented in `Godot iOS GameCenter plugin <https://github.com/godotengine/godot-ios-plugins/blob/master/plugins/gamecenter/game_center.mm>`_.
217238

218-
The Game Center API is available through the "GameCenter" singleton. It
239+
The Game Center API is available through the ``GameCenter`` singleton. It
219240
has the following methods:
220241

221242
::
@@ -495,34 +516,3 @@ On close:
495516
"type": "show_game_center",
496517
"result": "ok",
497518
}
498-
499-
Multi-platform games
500-
--------------------
501-
502-
When working on a multi-platform game, you won't always have the
503-
"GameCenter" singleton available (for example when running on PC or
504-
Android). Because the gdscript compiler looks up the singletons at
505-
compile time, you can't just query the singletons to see and use what
506-
you need inside a conditional block, you need to also define them as
507-
valid identifiers (local variable or class member). This is an example
508-
of how to work around this in a class:
509-
510-
::
511-
512-
var GameCenter = null # define it as a class member
513-
514-
func post_score(score):
515-
if GameCenter == null:
516-
return
517-
GameCenter.post_score({ "value": score, "category": "my_leaderboard" })
518-
519-
func check_events():
520-
while GameCenter.get_pending_event_count() > 0:
521-
# do something with events here
522-
pass
523-
524-
func _ready():
525-
# check if the singleton exists
526-
if Globals.has_singleton("GameCenter"):
527-
GameCenter = Globals.get_singleton("GameCenter")
528-
# connect your timer here to the "check_events" function

0 commit comments

Comments
 (0)