Present alerts on the window that exists, not the first one - #141
Open
cortfritz wants to merge 1 commit into
Open
Present alerts on the window that exists, not the first one#141cortfritz wants to merge 1 commit into
cortfritz wants to merge 1 commit into
Conversation
nif_alert_show and nif_action_sheet_show resolve their presenting controller through a private root_vc() that takes `scene.windows.firstObject` and reads its rootViewController. That assumes the app's window sorts first in the scene's window set. On iOS 26 it does not: the property comes back nil, root_vc() returns nil, the `if (vc)` guard drops the dialog, and nothing is logged. An alert simply never appears — on a physical iPhone 16 Pro (iOS 26.6.1) no confirm dialog could be shown at all. Core already has the right lookup in mob_root_vc, which tries `keyWindow` first and falls back to windows.firstObject, and the scanner and camera plugins each carry a copy of it (scan_root_vc, cam_root_vc). Those present fine on the same device and the same scene, which is what isolates the window lookup as the difference. Route root_vc through mob_root_vc and keep only the part that was doing real work — walking to the topmost presented controller. The activationState == ForegroundActive filter goes with it, matching mob_root_vc and the two plugin copies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On iOS 26,
Mob.Alert.alert/2andMob.Alert.action_sheet/2never show anything. No error, no log — the dialog is silently dropped.Cause
nif_alert_showandnif_action_sheet_showresolve their presenting controller through a privateroot_vc()that hand-rolls the window lookup:That assumes the app's window sorts first in the scene's window set. On iOS 26 it does not,
rootViewControlleris nil, and theif (vc)guard downstream discards the alert.Core already has the correct lookup one file over, in
mob_root_vc, which trieskeyWindowbefore falling back towindows.firstObjectand skips any window with no root controller. The scanner and camera plugins each carry a copy of it (scan_root_vc,cam_root_vc).That asymmetry is what isolates the cause: on the same device, in the same scene, the QR scanner and the camera present fine while the alert never does. The window lookup is the only structural difference between them.
Change
root_vc()now delegates tomob_root_vc()and keeps only the part that was doing real work — walking to the topmost presented controller. TheactivationState == UISceneActivationStateForegroundActivefilter goes with the hand-rolled loop, matchingmob_root_vcand both plugin copies.Verification
Rung 1 of the ladder, plus the field report that started it.
xcrun clang-format --dry-run -Werror ios/mob_nif.m— clean.clang -fsyntax-onlyagainst the iOS 26.5 SDK — no diagnostics introduced (identical output before and after).mob_scannerandmob_camerapresented normally in the same app. I attributed it to this function by inspection; I have not yet instrumentedroot_vc()returning nil, and I have not run the patched build on the device. Happy to do that if you want it before merging.Related:
issues.md§9 describesMob.Test.dismiss_alert/2failing on the simulator, which implies alerts do present there — so this may be device- or iOS-26-specific rather than universal.The companion PR fixes a use-after-free in the same two functions' button handlers, which bites as soon as a dialog does appear.
https://claude.ai/code/session_01FGHFA67yQndR78WYAU9DM7