Skip to content

Fix iOS 13+ multi-scene window handling and thread safety#1159

Open
AdrianCurtin wants to merge 23 commits intoSVProgressHUD:masterfrom
commandpostsoft:master
Open

Fix iOS 13+ multi-scene window handling and thread safety#1159
AdrianCurtin wants to merge 23 commits intoSVProgressHUD:masterfrom
commandpostsoft:master

Conversation

@AdrianCurtin
Copy link
Copy Markdown

@AdrianCurtin AdrianCurtin commented Dec 24, 2025

Summary

This PR consolidates multiple bug fixes to improve iOS 13+ compatibility, thread safety, and defensive nil handling.

iOS 13+ Multi-Scene Support

  • Rewrote +mainWindow to properly enumerate connected scenes and find the key window
  • Added CarPlay filtering via UIWindowSceneSessionRoleApplication check
  • Updated -frontWindow and -visibleKeyboardHeight for scene-based window discovery
  • Added proper fallbacks for pre-iOS 13 and edge cases where no active scene exists

Thread Safety

  • +popActivity now checks [NSThread isMainThread] and dispatches to main queue when needed
  • -showProgress:status: optimized to execute synchronously when already on main thread

Memory Management

  • Fixed weak/strong dance in -showProgress:status:, -showImage:status:duration:, and -dismissWithDelay:completion: to consistently use strongSelf

Nil Safety

  • Added nil check in +imageBundle before calling bundleWithURL:
  • Added containerView.window checks in -updateViewHierarchy and -moveToPoint:rotateAngle:
  • Added window && window.rootViewController check before adding HUD to window
  • Added nil check for rootController before calling setNeedsStatusBarAppearanceUpdate

Other

  • Fixed umbrella header warning by removing internal header symlinks
  • Replaced performSelector: with proper protocol conformance for UIWindowSceneDelegate

Closes

Merges

ibarisic05 and others added 19 commits September 13, 2018 00:09
Update CHANGELOG.md

Fix warning Umbrella header for module
Added a nil check before calling setNeedsStatusBarAppearanceUpdate on rootViewController to prevent potential crashes when rootViewController is not set.
Adds nil check before calling bundleWithURL: to prevent crash
when SVProgressHUD.bundle cannot be found.

Fixes SVProgressHUD#1146
Check if containerView.window exists before using containerView.
Falls back to frontWindow if containerView was deallocated.

Fixes SVProgressHUD#1121
Refactored window retrieval to use protocol conformance and property access for UIWindowSceneDelegate and UIApplicationDelegate. Improved thread safety in popActivity by checking for main thread before executing. Fixed potential nil window access and corrected usage of strongSelf in blocks for grace timer and image tinting.
Copilot AI review requested due to automatic review settings December 24, 2025 19:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances iOS 13+ multi-scene window handling and improves thread safety in SVProgressHUD. The changes address window hierarchy management in multi-scene environments, add proper thread safety checks for UI operations, and remove incorrect symlinks that were causing build warnings.

Key Changes:

  • Improved window discovery logic with proper iOS 13+ multi-scene support, including fallback mechanisms for finding the correct window
  • Added thread safety checks to ensure UI operations execute on the main thread
  • Fixed memory management issues by using strongSelf consistently instead of self in completion blocks

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
SVProgressHUD/SVProgressHUD.m Core implementation updates including multi-scene window handling, thread safety improvements, and bug fixes for proper window hierarchy validation
SVProgressHUD/include/SVRadialGradientLayer.h Removed incorrect symlink to fix umbrella header warnings
SVProgressHUD/include/SVProgressAnimatedView.h Removed incorrect symlink to fix umbrella header warnings
SVProgressHUD/include/SVIndefiniteAnimatedView.h Removed incorrect symlink to fix umbrella header warnings
CHANGELOG.md Added version 2.3.2 entry documenting the umbrella header fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Added tvOS 13.0 availability checks alongside iOS 13.0 for better platform compatibility. Improved logic to ensure mainWindow is only set if sceneDelegate.window exists, and made minor code style adjustments for consistency.
@AdrianCurtin
Copy link
Copy Markdown
Author

@juliensaad

This is a sort of bundled PR to close a bunch of open stability issues with the library, please review and comment as you see fit.

Added detailed entries for version 2.3.2, including fixes for iOS multi-scene window handling, CarPlay crashes, thread safety, and memory management improvements. Also noted tvOS 13.0 availability checks and clarified previous fixes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread SVProgressHUD/SVProgressHUD.m
Comment thread SVProgressHUD/SVProgressHUD.m
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
Comment thread SVProgressHUD/SVProgressHUD.m Outdated
@PasqualePuzio
Copy link
Copy Markdown

@AdrianCurtin could you please explain how issue #1153 was fixed by this pull request? What was the root cause? Thanks

@AdrianCurtin
Copy link
Copy Markdown
Author

AdrianCurtin commented Mar 16, 2026

"return windowScene.windows.firstObject;" was returning the wrong window (or nil) on iOS 26.

The old code grabbed windowScene.windows.firstObject, which on iOS 26's stricter scene lifecycle is often not the key window It could be a system window or one that's hidden. So the HUD was being added to a non-visible window. Now it checks window.isKeyWindow && !window.isHidden, with multiple fallback layers (inactive scenes, delegate windows) if the first pass doesn't find one. Some other stuff isn't guaranteed to be called from the main thread so its essentilally a race condition.

Restrict scene handling to application-role UIWindowScenes on iOS/tvOS 13+. When searching for the keyboard window and the active foreground window, the code now checks scene.session.role == UIWindowSceneSessionRoleApplication before iterating windows. This avoids picking up non-application scenes (e.g. system, external, or keyboard-only scenes) and makes window selection more robust on multi-scene environments. No behavioral changes for earlier OS versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment