Files
real-e-party-iOS/YuMi/Appdelegate/AppDelegate.m
edwinQQQ 37e105f04f refactor: 移除友盟相关代码并清理项目结构
主要变更:
1. 从 Podfile 中移除 UMCommon 和 UMDevice 依赖,简化项目依赖管理。
2. 从 AppDelegate 中移除友盟初始化代码,减少不必要的依赖。
3. 删除 GlobalEventManager 相关文件,清理未使用的代码。

此更新旨在提升项目的可维护性,减少冗余依赖,确保代码结构更加清晰。
2025-10-20 14:32:43 +08:00

340 lines
13 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 <MobLinkPro/MobLink.h>
#import <MobLinkPro/MLSDKScene.h>
#import "TabbarViewController.h"
#import "BaseNavigationController.h"
#import "AppDelegate+ThirdConfig.h"
#import <NIMSDK/NIMSDK.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import "ClientConfig.h"
#import <GoogleSignIn/GoogleSignIn.h>
#import <GoogleSignIn/GoogleSignIn.h>
#import "LoginViewController.h"
#import "AccountModel.h"
#import "YuMi-swift.h"
#import "SessionViewController.h"
#import "LoginFullInfoViewController.h"
#import "UIView+VAP.h"
#import "SocialShareManager.h"
#import "EPSignatureColorGuideView.h"
#import "EPEmotionColorStorage.h"
UIKIT_EXTERN NSString * const kOpenRoomNotification;
@interface AppDelegate ()<IMLSDKRestoreDelegate>
@end
@implementation AppDelegate
//日志接口
void qg_VAP_Logger_handler(VAPLogLevel level, const char* file, int line, const char* func, NSString *module, NSString *format, ...) {
// 屏蔽 MP4 播放 log
return;
// if (format.UTF8String == nil) {
// NSLog(@"log包含非utf-8字符");
// return;
// }
// if (level > VAPLogLevelDebug) {
// va_list argList;
// va_start(argList, format);
// NSString* message = [[NSString alloc] initWithFormat:format arguments:argList];
// file = [NSString stringWithUTF8String:file].lastPathComponent.UTF8String;
// NSLog(@"<%@> %s(%@):%s [%@] - %@",@(level), file, @(line), func, module, message);
// va_end(argList);
// }
}
- (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];
[VAPView registerHWDLog:qg_VAP_Logger_handler];
///初始化一些 sdk配置
[self initThirdConfig];
[self initUM:application launchOptions:launchOptions];
@kWeakify(self);
[[ClientConfig shareConfig] clientConfig:^{
@kStrongify(self);
dispatch_async(dispatch_get_main_queue(), ^{
[self loadMainPage];
[self setupLaunchADView];
});
}];
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)initUM:(UIApplication *)application
launchOptions:(NSDictionary *)launchOptions {
// 初始化 MobLink
[MobLink setDelegate:self];
}
- (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];
});
}
[[ClientConfig shareConfig] clientInit];
}
/// 检查并显示专属颜色引导页
- (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;
// 旧代码保留注释(便于回滚)
// LoginViewController *lvc = [[LoginViewController alloc] init];
// BaseNavigationController * navigationController = [[BaseNavigationController alloc] initWithRootViewController:lvc];
// navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
// self.window.rootViewController = navigationController;
}
- (void)toHomeTabbarPage {
// ========== 白牌版本:使用新的 EPTabBarController ==========
EPTabBarController *epTabBar = [EPTabBarController create];
[epTabBar refreshTabBarWithIsLogin:YES];
UIWindow *window = [self getKeyWindow];
if (window) {
window.rootViewController = epTabBar;
[window makeKeyAndVisible];
}
NSLog(@"[AppDelegate] 自动登录后已切换到白牌 TabBarEPTabBarController");
// ========== 原代码(已注释) ==========
/*
TabbarViewController *vc = [[TabbarViewController alloc] init];
BaseNavigationController *navigationController = [[BaseNavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = navigationController;
*/
}
- (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene
Restore:(void (^)(BOOL, RestoreStyle))restoreHandler {
NSString *inviteCode = scene.params[@"inviteCode"];
if (inviteCode != nil && [[AccountInfoStorage instance]getUid].length == 0){
ClientConfig *config = [ClientConfig shareConfig];
config.inviteCode = inviteCode;
}
restoreHandler(YES, MLDefault);
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSInteger count = [NIMSDK sharedSDK].conversationManager.allUnreadCount;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}
- (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:
// NSLog(@"用户拒绝IDFA");
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
// NSLog(@"用户允许IDFA");
break;
case ATTrackingManagerAuthorizationStatusNotDetermined: {
// NSLog(@"用户未做选择或未弹窗IDFA");
//请求弹出用户授权框只会在程序运行是弹框1次除非卸载app重装通地图、相机等权限弹框一样
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// NSLog(@"app追踪IDFA权限%lu",(unsigned long)status);
}];
}
break;
default:
break;
}
}
});
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// 上传devicetoken至云信服务器。
[[NIMSDK sharedSDK] updateApnsToken:deviceToken ];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSString *data = userInfo[@"data"];
if(data){
NSDictionary *dataDic = [data mj_JSONObject];
NSString *userId = dataDic[@"uid"];
if(userId){
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"type":@"kOpenChat",@"uid":userId,@"isNoAttention":@(YES)}];
ClientConfig *config = [ClientConfig shareConfig];
config.pushChatId = userId;
});
return;
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSString *userId = userInfo[@"uid"];
if(userId){
[[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"type":@"kOpenChat",@"uid":userId,@"isNoAttention":@(YES)}];
ClientConfig *config = [ClientConfig shareConfig];
config.pushChatId = userId;
}
});
}
///URL Scheme跳转
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
[[SocialShareManager sharedManager] handleURL:url];
return [GIDSignIn.sharedInstance handleURL:url];
}
//- (void)__oldApplicationOpenURLMethod:(NSURL *)url {
// NSString *text = [url query];
// if(text.length){
// NSMutableDictionary *paramsDict = [NSMutableDictionary dictionary];
// NSArray *paramArray = [text componentsSeparatedByString:@"&"];
// for (NSString *param in paramArray) {
// if (param && param.length) {
// NSArray *parArr = [param componentsSeparatedByString:@"="];
// if (parArr.count == 2) {
// [paramsDict setObject:parArr[1] forKey:parArr[0]];
// }
// }
// }
// if(paramsDict[@"type"] != nil){
// NSInteger type = [paramsDict[@"type"] integerValue];
// if (type == 2) {
// NSString *uid = [NSString stringWithFormat:@"%@",paramsDict[@"uid"]];
// [[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"uid":uid}];
// ClientConfig *config = [ClientConfig shareConfig];
// config.roomId = uid;
// }else if(type == 7){
// NSString *uid = [NSString stringWithFormat:@"%@",paramsDict[@"uid"]];
// [[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"type":@"kOpenChat",@"uid":uid}];
// ClientConfig *config = [ClientConfig shareConfig];
// config.chatId = uid;
// }else if (type == 8){
// NSString *inviteCode = paramsDict[@"inviteCode"];
// if (inviteCode != nil && [[AccountInfoStorage instance]getUid].length == 0){
// ClientConfig *config = [ClientConfig shareConfig];
// config.inviteCode = inviteCode;
// }
// }
//// return YES;
// }
// }
//}
@end