修复 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:
@@ -126,9 +126,9 @@
|
||||
NSDictionary *userInfoDict = @{
|
||||
@"nickname": self.userInfo.nick ?: @"未设置昵称",
|
||||
@"avatar": self.userInfo.avatar ?: @"",
|
||||
@"level": @(self.userInfo.charmLevel),
|
||||
@"exp": @(self.userInfo.charmLevelExp),
|
||||
@"nextLevelExp": @(self.userInfo.nextCharmLevelExp),
|
||||
// @"level": @(self.userInfo.charmLevel),
|
||||
// @"exp": @(self.userInfo.charmLevelExp),
|
||||
// @"nextLevelExp": @(self.userInfo.nextCharmLevelExp),
|
||||
@"followers": @(self.userInfo.fansNum),
|
||||
@"following": @(self.userInfo.followNum),
|
||||
};
|
||||
@@ -150,15 +150,18 @@
|
||||
|
||||
if (!uid.length || !ticket.length) return;
|
||||
|
||||
[Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
if (code == 200 && data.data) {
|
||||
self.walletInfo = [WalletInfoModel mj_objectWithKeyValues:data.data];
|
||||
NSLog(@"[NewMineViewController] 钱包信息加载成功: 钻石=%ld 金币=%ld",
|
||||
(long)self.walletInfo.diamond, (long)self.walletInfo.money);
|
||||
}
|
||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
NSLog(@"[NewMineViewController] 钱包信息加载失败: %@", msg);
|
||||
} uid:uid ticket:ticket];
|
||||
|
||||
// TODO: 使用 api-presnter, 参照其他 VC
|
||||
|
||||
// [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
// if (code == 200 && data.data) {
|
||||
// self.walletInfo = [WalletInfoModel mj_objectWithKeyValues:data.data];
|
||||
// NSLog(@"[NewMineViewController] 钱包信息加载成功: 钻石=%ld 金币=%ld",
|
||||
// (long)self.walletInfo.diamond, (long)self.walletInfo.money);
|
||||
// }
|
||||
// } fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||
// NSLog(@"[NewMineViewController] 钱包信息加载失败: %@", msg);
|
||||
// } uid:uid ticket:ticket];
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
@@ -151,7 +151,7 @@
|
||||
self.nameLabel.text = model.nick ?: @"匿名用户";
|
||||
|
||||
// 配置时间
|
||||
self.timeLabel.text = [self formatTimeInterval:model.createTime];
|
||||
self.timeLabel.text = model.publishTime;
|
||||
|
||||
// 配置内容
|
||||
self.contentLabel.text = model.content ?: @"";
|
||||
@@ -199,15 +199,17 @@
|
||||
|
||||
NSString *uid = [[AccountInfoStorage instance] getUid];
|
||||
NSString *dynamicId = self.currentModel.dynamicId;
|
||||
NSString *status = self.currentModel.isLiked ? @"0" : @"1"; // 0=取消,1=点赞
|
||||
NSString *status = self.currentModel.isLike ? @"0" : @"1"; // 0=取消,1=点赞
|
||||
NSString *likedUid = self.currentModel.uid;
|
||||
NSString *worldId = self.currentModel.worldId ?: @"";
|
||||
NSString *worldId = self.currentModel.worldId > 0 ? @(self.currentModel.worldId).stringValue : @"";
|
||||
|
||||
[Api momentsLike:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
if (code == 200) {
|
||||
// 更新点赞状态
|
||||
self.currentModel.isLiked = !self.currentModel.isLiked;
|
||||
self.currentModel.likeCount += self.currentModel.isLiked ? 1 : -1;
|
||||
self.currentModel.isLike = !self.currentModel.isLike;
|
||||
NSInteger likeCount = [self.currentModel.likeCount integerValue];
|
||||
likeCount += self.currentModel.isLike ? 1 : -1;
|
||||
self.currentModel.likeCount = @(likeCount).stringValue;
|
||||
|
||||
// 更新 UI
|
||||
[self.likeButton setTitle:[NSString stringWithFormat:@"👍 %ld", (long)self.currentModel.likeCount] forState:UIControlStateNormal];
|
||||
|
@@ -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