Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ cat > MyGame.app/Info.plist << EOF
<string>1</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
EOF
Expand All @@ -148,6 +163,8 @@ xcrun simctl install booted MyGame.app/
xcrun simctl launch booted com.mygame
```

Apps built with the iOS 27 SDK need the `UIApplicationSceneManifest` entry, or iOS refuses to launch them. miniquad creates the window itself, so the manifest doesn't need a `UISceneDelegateClassName`.

For details and instructions on provisioning for real iphone, check [https://macroquad.rs/articles/ios/](https://macroquad.rs/articles/ios/)

## Cross Compilation
Expand Down
54 changes: 35 additions & 19 deletions src/native/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,36 @@ use {

// iOS 27 / TN3187: windows must be created via `initWithWindowScene:`
// or they stay invisible. Window creation defers to the
// `UISceneWillConnectNotification` observer below; both that and
// `did_finish_launching_with_options` run on the main thread, so
// `UISceneWillConnectNotification` observer below, or to the end of
// `did_finish_launching_with_options` when the scene is already
// connected; both run on the main thread, so
// `thread_local` storage is sound.
thread_local! {
static PENDING_SCENE_VIEW_AND_CTRL: RefCell<Option<(ObjcId, ObjcId)>> =
RefCell::new(None);
}

/// Puts the pending view and view controller in a new window on `scene`.
/// Runs once: whichever caller sees the scene first takes the pair.
unsafe fn attach_to_scene(scene: ObjcId) {
let is_window_scene: BOOL = msg_send![scene, isKindOfClass: class!(UIWindowScene)];
if is_window_scene == NO {
return;
}

let (view, view_ctrl) = match PENDING_SCENE_VIEW_AND_CTRL.with(|cell| cell.borrow_mut().take())
{
Some(pair) => pair,
None => return,
};

let window: ObjcId = msg_send![class!(UIWindow), alloc];
let window: ObjcId = msg_send![window, initWithWindowScene: scene];
msg_send_![window, addSubview: view];
msg_send_![window, setRootViewController: view_ctrl];
msg_send_![window, makeKeyAndVisible];
}

struct MainThreadState {
quit: bool,
paused: bool,
Expand Down Expand Up @@ -694,6 +716,16 @@ pub fn define_app_delegate() -> *const Class {
name: scene_did_activate_name
object: nil];

// Without `UIApplicationSceneManifest` in Info.plist, UIKit
// connects the scene before this method runs, so the
// notification above was already posted. Attach to it here.
let app: ObjcId = msg_send![class!(UIApplication), sharedApplication];
let scenes: ObjcId = msg_send![app, connectedScenes];
let scene: ObjcId = msg_send![scenes, anyObject];
if !scene.is_null() {
attach_to_scene(scene);
}

// No background render thread — `CADisplayLink` drives
// `drawInMTKView:` directly.
}
Expand All @@ -711,23 +743,7 @@ pub fn define_app_delegate() -> *const Class {
extern "C" fn scene_will_connect(_: &Object, _: Sel, notification: ObjcId) {
unsafe {
let scene: ObjcId = msg_send![notification, object];
let is_window_scene: BOOL =
msg_send![scene, isKindOfClass: class!(UIWindowScene)];
if is_window_scene == NO {
return;
}

let (view, view_ctrl) =
match PENDING_SCENE_VIEW_AND_CTRL.with(|cell| cell.borrow_mut().take()) {
Some(pair) => pair,
None => return,
};

let window: ObjcId = msg_send![class!(UIWindow), alloc];
let window: ObjcId = msg_send![window, initWithWindowScene: scene];
msg_send_![window, addSubview: view];
msg_send_![window, setRootViewController: view_ctrl];
msg_send_![window, makeKeyAndVisible];
attach_to_scene(scene);
}
}

Expand Down
Loading