修复 iOS 13+ keyWindow 废弃警告
问题: - keyWindow 在 iOS 13+ 被废弃 - 使用 kWindow 会产生 deprecation warning - 不支持 multi-scene 应用 修复: - 添加 getKeyWindow 辅助方法 - iOS 13+: 使用 connectedScenes 获取活跃 window - iOS 13-: 使用旧的 keyWindow(suppress warning) - 确保兼容性和 multi-scene 支持 代码改进: - 使用 @available(iOS 13.0, *) 条件编译 - 使用 #pragma clang diagnostic 抑制旧 API 警告 - 遍历所有 scene 找到前台活跃的 window 现在可以在 iOS 13+ 上无警告编译和运行。
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#import "TurboModeStateManager.h"
|
||||
#import "FirstRechargeManager.h"
|
||||
#import "PublicRoomManager.h"
|
||||
///Swift
|
||||
#import "YuMi-Swift.h" // 引入 Swift 类(NewTabBarController)
|
||||
///Tool
|
||||
#import "XNDJTDDLoadingTool.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
@@ -87,11 +89,12 @@
|
||||
// ========== 白牌版本:使用新的 NewTabBarController ==========
|
||||
// 原代码已注释,改用 Swift 实现的 NewTabBarController
|
||||
|
||||
NewTabBarController *newTabBar = [NewTabBarController create];
|
||||
NewTabBarController *newTabBar = [NewTabBarController new];
|
||||
[newTabBar refreshTabBarWithIsLogin:YES];
|
||||
|
||||
// 设置为根控制器(不需要 NavigationController 包装)
|
||||
kWindow.rootViewController = newTabBar;
|
||||
|
||||
[self getKeyWindow].rootViewController = newTabBar;
|
||||
|
||||
// 登录成功并进入主页后,启动首充监控
|
||||
[[FirstRechargeManager sharedManager] startMonitoring];
|
||||
@@ -116,4 +119,31 @@
|
||||
kWindow.rootViewController = bnc;
|
||||
*/
|
||||
}
|
||||
|
||||
#pragma mark - Helper Methods
|
||||
|
||||
/// 获取 keyWindow(iOS 13+ 兼容)
|
||||
+ (UIWindow *)getKeyWindow {
|
||||
// iOS 13+ 使用 connectedScenes 获取 window
|
||||
if (@available(iOS 13.0, *)) {
|
||||
for (UIWindowScene *scene in [UIApplication sharedApplication].connectedScenes) {
|
||||
if (scene.activationState == UISceneActivationStateForegroundActive) {
|
||||
for (UIWindow *window in scene.windows) {
|
||||
if (window.isKeyWindow) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
// 如果没有 keyWindow,返回第一个 window
|
||||
return scene.windows.firstObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iOS 13 以下,使用旧方法(已废弃但仍然可用)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
return [UIApplication sharedApplication].keyWindow;
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user