# iOS

> The iOS target: an Xcode project generated by XcodeGen from the .toml, raylib from a pinned fork, an entry point UIKit calls, an app that must not quit, and signing that stays out of CI.

Source: https://omardev29.github.io/rmp-docs/manual/platforms/ios.html

iOS is the target that differs most from the others, in three ways. It is built by Xcode rather than CMake, from a project generated out of `raylib_multiplatform.toml`. Upstream raylib has no iOS backend, so raylib comes prebuilt from a fork. And the app does not own its frame loop or its own ending: UIKit does, and Apple rejects an app that quits.

## Building it

Building for iOS needs a Mac with Xcode, and XcodeGen to turn the generated description into an Xcode project. The steps, from the game's folder:

```shell
git submodule update --init thirdparty/raylib-ios    # the raylib-iOS fork; a clone leaves it empty
python3 tools/configure.py                           # writes ios/project.yml from the .toml
(cd thirdparty/raylib-ios/projects/scripts && bash build-ios-xcframework.sh)   # device + simulator
cd ios
xcodegen generate                                    # ios/my_game.xcodeproj
open my_game.xcodeproj
```

`raylib.xcframework` is built once, and again only when the submodule moves. Run `configure.py` with the submodule in place: it is what writes the iOS licence notice, which credits the fork.

A simulator build needs no signing at all, and is what CI builds:

```shell
xcodebuild -project my_game.xcodeproj -scheme my_game \
    -destination 'generic/platform=iOS Simulator' CODE_SIGNING_ALLOWED=NO build
```

### The raylib-iOS fork

`thirdparty/raylib-ios` is a git submodule, which `rmp new` leaves empty until you ask for it — it is only needed to build for iOS. It points at `omardev29/raylib-iOS`, a fork of the community project `ghera/raylib-iOS`, pinned at one commit. The fork exists for availability only: a submodule that points at somebody else's repository fails for ever the day that repository goes away.

The fork is what gives raylib an iOS backend: UIKit for the app, and OpenGL ES 3.0 through ANGLE, which runs it on Metal. Its script builds raylib into `raylib.xcframework`, with a device slice and the simulator's, and the app embeds ANGLE's two frameworks next to it. Because raylib comes prebuilt, `[raylib] disabled_modules` cannot reach it, and `configure.py` says so when both are set: `[raylib] disabled_modules has no effect on iOS: it links the prebuilt raylib.xcframework from
the pinned fork, which is built without these flags.`

## What the .toml decides

`configure.py` writes `ios/project.yml`, XcodeGen's description of the project, and nothing in it is meant to be edited by hand: it is regenerated on every configure, and not committed. What goes into it:

| From | Becomes |
|---|---|
| `[ios] bundle_id` | The bundle identifier: the app's identity on the App Store. |
| `[ios] deployment_target` | The oldest iOS the app runs on. 13.0 at the least; 15.6 by default. |
| `[project] name` | The product, the scheme and the Xcode project's name. |
| `[window] title` | The name under the app's icon. |
| `[window] orientation` | The supported orientations: both landscapes, portrait, or all three for `"unspecified"`. The same key sets Android. |
| `[icon] source` | The app icon. |
| `[ios.settings]` | Raw Xcode build settings, copied in as they are — except an `OTHER_CPLUSPLUSFLAGS` of yours, which is added after the framework's own flags in that setting rather than replacing them. |
| the git tag | The marketing version. |

The rest is fixed: the game's `src/` and `include/` as sources; the whole of `resources/` copied into the app as a folder; the licence notices; a launch screen Xcode generates, without which iOS would run the game letterboxed at a legacy resolution; full screen with the status bar hidden; RMP_PRODUCTION_BUILD at 0 in the Debug configuration and 1 in Release; and C++20, with `-Werror=reorder-init-list`, the flag the CMake and Android builds give Clang: a designated initialiser out of declaration order is a compile error in Xcode too, as it is with GCC and MSVC, and not a warning that passes on one machine and fails on another.

The deployment target has a floor because of [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html): it uses `std::filesystem`, which Apple's C++ library only has from iOS 13. Below that the configuration is refused, rather than failing in the compiler later:

```toml
[ios]
deployment_target = "12.4"
```

```text
  raylib_multiplatform.toml:2: deployment_target = "12.4"
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^

  configure: error: [ios] deployment_target = '12.4' is below 13.0.
                    rmp::save uses std::filesystem, which Apple's C++ library only has from iOS 13. Use 13.0 or later; the default, 15.6, covers every iPhone Apple still updates.
```

A bundle id may contain hyphens, which an Android application id may not, and like the Android id, a `com.example.` placeholder is refused for a release.

## The entry point

On every other target the game has a `main()`. On iOS it does not: UIKit owns the run loop, and raylib's iOS backend calls three functions instead — one when the app is ready, one per frame, one when it is destroyed. [`RMP_GAME`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_GAME) writes those three on iOS — it expands to [`RMP_IOS_FUNCS`](https://omardev29.github.io/rmp-docs/reference/macros.html#RMP_IOS_FUNCS) there — and nothing in the game changes.

The process does not start inside the app's bundle, where `resources/` is, so before anything loads the framework moves into it. The bundle is read-only; saves go to the app's `Library/Application Support/` instead — not to `Documents/`, which the Files app shows and Apple's storage guidelines keep for what the user made.

The frame is paced by the display: `[window] fps` is ignored, and the framework never calls `SetTargetFPS()` there.

## An iOS app does not quit

Apple is explicit about it, in its Q&A 1561: an app that ends itself "will appear to the user to have crashed", and App Review rejects apps that crash or look as if they did. A control whose job is to quit fails the Human Interface Guidelines on its own.

So [`rmp::app::quit()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-app.html#quit) does nothing on iOS. It says once, `APP: quit() does nothing on iOS — Apple rejects apps that terminate themselves
(QA1561). Ignoring.`, and returns. The same source keeps its Quit button and ships everywhere; on an iPhone the button is simply inert. To leave it off the screen there instead:

```cpp
rmp::ui::begin();
if (rmp::ui::button("Play")) rmp::Scene::pop();
#if !defined(PLATFORM_IOS)
if (rmp::ui::button("Quit")) rmp::app::quit();
#endif
rmp::ui::end();
```

That message is a framework warning like the others, so with `[dev] strict = true` it stops a debug build where the button was pressed — a reminder to hide the button. For the same reason the framework refuses to pop the last scene off the stack: on iOS there would be no way back.

## Signing stays out of CI

Nothing built in CI can be installed on an iPhone. Apple requires a signed app, and signing needs a paid Apple Developer account, a certificate and a provisioning profile — none of which belongs in a public repository or in CI. What CI builds is a simulator app, with signing switched off.

For a device, open the generated project on a Mac. Put your team in the `.toml` rather than clicking it into Xcode, so it survives the next regeneration — a team id is an identifier, not a secret:

```toml
[ios.settings]
DEVELOPMENT_TEAM = "ABCDE12345"
CODE_SIGN_STYLE = "Automatic"
```

Then choose the device in Xcode and run. TestFlight and the App Store go through an archive made in Xcode; that path is not automated, because it needs credentials that should not live in CI.

The simulator app CI builds is attached to a release as `ios-app-simulator.zip`, next to `ios-raylib-xcframework.zip`, the raylib it was built with, and runs on a Mac's simulator:

```shell
unzip ios-app-simulator.zip
xcrun simctl boot "iPhone 16"
open -a Simulator
xcrun simctl install booted my_game.app
xcrun simctl launch --console booted com.yourname.yourgame
```

## What CI checks

iOS is in the full lane: on a release, or when the full lane is asked for. On a pinned macOS runner and a pinned Xcode, CI builds the xcframework from the fork, generates the project, builds the simulator app, unsigned, and checks the bundle: that its executable is a Mach-O, that it has an `Info.plist` with a bundle identifier, and that `resources/` is inside it. Starting the app in the simulator is a step of its own, run only when the repository variable `IOS_SIMULATOR_TEST` is `true`: the simulator on the hosted runners does not boot reliably, and a gate that fails for the runner's reasons would teach everyone to ignore it.

`[upx]` refuses `ios` by name, at its line, when the configuration is checked: the app is signed, and compressing it would break the signature.
