Files
real-e-party-iOS/YuMi/Appdelegate/AppDelegate.m
2025-10-17 14:03:50 +08:00

177 lines
6.0 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppDelegate.m
// YUMI
//
// Created by admin on 2023/3/9.
//
#import "AppDelegate.h"
#import "BaseNavigationController.h"
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import "YuMi-swift.h"
UIKIT_EXTERN NSString * const kOpenRoomNotification;
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *launchStoryboard = [UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil];
UIViewController *launchScreenVC = [launchStoryboard instantiateInitialViewController];
self.window.rootViewController = launchScreenVC;
[self.window makeKeyAndVisible];
[self loadMainPage];
if (@available(iOS 15, *)) {
[[UITableView appearance] setSectionHeaderTopPadding:0];
}
return YES;
}
// MARK: - Helper Methods
/// 获取 keyWindowiOS 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
}
- (void)loadMainPage {
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
if (accountModel == nil ||
accountModel.uid == nil ||
accountModel.access_token == nil) {
[self toLoginPage];
}else{
[self toHomeTabbarPage];
// 延迟检查专属颜色(等待 window 初始化完成)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self checkAndShowSignatureColorGuide];
});
}
}
/// 检查并显示专属颜色引导页
- (void)checkAndShowSignatureColorGuide {
UIWindow *keyWindow = [self getKeyWindow];
if (!keyWindow) return;
BOOL hasSignatureColor = [EPEmotionColorStorage hasUserSignatureColor];
#if DEBUG
// Debug 环境:总是显示引导页
NSLog(@"[AppDelegate] Debug 模式:显示专属颜色引导页(已有颜色: %@", hasSignatureColor ? @"YES" : @"NO");
EPSignatureColorGuideView *guideView = [[EPSignatureColorGuideView alloc] init];
// 设置颜色确认回调
guideView.onColorConfirmed = ^(NSString *hexColor) {
[EPEmotionColorStorage saveUserSignatureColor:hexColor];
NSLog(@"[AppDelegate] 用户选择专属颜色: %@", hexColor);
};
// 如果已有颜色,设置 Skip 回调
if (hasSignatureColor) {
guideView.onSkipTapped = ^{
NSLog(@"[AppDelegate] 用户跳过专属颜色选择");
};
}
// 显示引导页,已有颜色时显示 Skip 按钮
[guideView showInWindow:keyWindow showSkipButton:hasSignatureColor];
#else
// Release 环境:仅在未设置专属颜色时显示
if (!hasSignatureColor) {
EPSignatureColorGuideView *guideView = [[EPSignatureColorGuideView alloc] init];
guideView.onColorConfirmed = ^(NSString *hexColor) {
[EPEmotionColorStorage saveUserSignatureColor:hexColor];
NSLog(@"[AppDelegate] 用户选择专属颜色: %@", hexColor);
};
[guideView showInWindow:keyWindow];
}
#endif
}
- (void)toLoginPage {
// 使用新的 Swift 登录页面
EPLoginViewController *lvc = [[EPLoginViewController alloc] init];
BaseNavigationController *navigationController =
[[BaseNavigationController alloc] initWithRootViewController:lvc];
navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
self.window.rootViewController = navigationController;
}
- (void)toHomeTabbarPage {
EPTabBarController *epTabBar = [EPTabBarController create];
[epTabBar refreshTabBarWithIsLogin:YES];
UIWindow *window = [self getKeyWindow];
if (window) {
window.rootViewController = epTabBar;
[window makeKeyAndVisible];
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self getAdvertisingTrackingAuthority];
[[NSNotificationCenter defaultCenter]postNotificationName:@"kAppDidBecomeActive" object:nil];
}
- (void)getAdvertisingTrackingAuthority {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (@available(iOS 14, *)) {
ATTrackingManagerAuthorizationStatus status = ATTrackingManager.trackingAuthorizationStatus;
switch (status) {
case ATTrackingManagerAuthorizationStatusDenied:
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
break;
case ATTrackingManagerAuthorizationStatusNotDetermined: {
// NSLog(@"用户未做选择或未弹窗IDFA");
//请求弹出用户授权框只会在程序运行是弹框1次除非卸载app重装通地图、相机等权限弹框一样
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// NSLog(@"app追踪IDFA权限%lu",(unsigned long)status);
}];
}
break;
default:
break;
}
}
});
}
@end