Skip to content

fix: iOS synchronize set safeAreaInset#1007

Open
RoeKun wants to merge 3 commits intoTencent-TDS:mainfrom
RoeKun:personal/valo_synchronize_safeAreaInsets_set
Open

fix: iOS synchronize set safeAreaInset#1007
RoeKun wants to merge 3 commits intoTencent-TDS:mainfrom
RoeKun:personal/valo_synchronize_safeAreaInsets_set

Conversation

@RoeKun
Copy link
Collaborator

@RoeKun RoeKun commented Feb 3, 2026

fix: iOS synchronize set safeAreaInset

@RoeKun RoeKun requested a review from wwwcg as a code owner February 3, 2026 09:40
@RoeKun RoeKun force-pushed the personal/valo_synchronize_safeAreaInsets_set branch from 7d04072 to 631f5c9 Compare February 5, 2026 06:16
@RoeKun RoeKun force-pushed the personal/valo_synchronize_safeAreaInsets_set branch from e1296af to 909ae3e Compare February 6, 2026 09:11
Comment on lines 742 to 754

/**
* 获取当前 KeyWindow
* 兼容 iOS 13+ 的 Scene 架构,替代废弃的 UIApplication.sharedApplication.keyWindow
*/
+ (UIWindow *)keyWindow {
#if TARGET_OS_OSX
return nil;
#else
if ([UIApplication isAppExtension]) {
return nil;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

mac上永远返回nil,不符合函数意义

Comment on lines 289 to 316
- (UIWindow *)viewControllerHostWindow {
#if !TARGET_OS_OSX
// 判断当前应用是否和用户交互过,避免vc初始化时UISceneActivationStateForegroundInactive导致拿到的safeAreaInsets是全零
UIApplicationState appState = UIApplication.sharedApplication.applicationState;

for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
BOOL isForegroundActive = (scene.activationState == UISceneActivationStateForegroundActive);
BOOL isForegroundInactive = (scene.activationState == UISceneActivationStateForegroundInactive);

// App 已活跃时只接受 Active,否则 Active 和 Inactive 都可以
BOOL isValidState = isForegroundActive || (appState != UIApplicationStateActive && isForegroundInactive);
if (isValidState && [scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *windowScene = (UIWindowScene *)scene;
if (!windowScene) {
continue;
}
for (UIWindow *window in windowScene.windows) {
if (window.isKeyWindow) {
return window;
}
}
}
}
#endif
return nil;
}


Copy link
Collaborator

Choose a reason for hiding this comment

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

文档不合适,修改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants