Files
peko-ios/YuMi/Appdelegate/AppDelegate.m

327 lines
13 KiB
Mathematica
Raw Normal View History

2023-07-06 16:54:13 +08:00
//
// AppDelegate.m
// YUMI
//
// Created by admin on 2023/3/9.
//
#import "AppDelegate.h"
#import <UMCommon/UMCommon.h>
2024-03-20 19:55:26 +08:00
#import <MobLinkPro/MobLink.h>
#import <MobLinkPro/MLSDKScene.h>
2023-07-14 18:50:55 +08:00
#import "TabbarViewController.h"
#import "BaseNavigationController.h"
2023-07-06 16:54:13 +08:00
#import "AppDelegate+ThirdConfig.h"
#import <NIMSDK/NIMSDK.h>
2023-08-16 14:21:58 +08:00
#import <AppTrackingTransparency/AppTrackingTransparency.h>
2023-08-17 18:26:13 +08:00
#import "ClientConfig.h"
2023-09-22 20:23:33 +08:00
#import <GoogleSignIn/GoogleSignIn.h>
#import <GoogleSignIn/GoogleSignIn.h>
2025-03-14 19:43:04 +08:00
#import "LoginViewController.h"
2023-10-07 18:42:30 +08:00
#import "AccountModel.h"
2023-12-29 16:43:37 +08:00
#import "YuMi-swift.h"
2024-02-21 10:18:59 +08:00
#import "SessionViewController.h"
2024-03-19 14:48:45 +08:00
#import "LoginFullInfoViewController.h"
#import "UIView+VAP.h"
2025-03-21 16:19:07 +08:00
#import "SocialShareManager.h"
2023-08-11 14:46:56 +08:00
UIKIT_EXTERN NSString * const kOpenRoomNotification;
2023-08-08 16:48:02 +08:00
2024-03-20 19:55:26 +08:00
@interface AppDelegate ()<IMLSDKRestoreDelegate>
2023-07-06 16:54:13 +08:00
@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);
// }
}
2023-07-06 16:54:13 +08:00
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2023-07-06 16:54:13 +08:00
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
2024-11-06 17:57:32 +08:00
UIStoryboard *launchStoryboard = [UIStoryboard storyboardWithName:@"Launch Screen" bundle:nil];
UIViewController *launchScreenVC = [launchStoryboard instantiateInitialViewController];
self.window.rootViewController = launchScreenVC;
2023-07-06 16:54:13 +08:00
[self.window makeKeyAndVisible];
[VAPView registerHWDLog:qg_VAP_Logger_handler];
2024-11-06 17:57:32 +08:00
/// 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;
}
- (void)initUM:(UIApplication *)application
launchOptions:(NSDictionary *)launchOptions {
//
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kYouMinumbernnagna"]) {
///
[UMConfigure initWithAppkey:@"6434c6dfd64e686139618269"
channel:@"appstore"];
}
2024-03-20 19:55:26 +08:00
[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];
}
2025-01-07 20:07:54 +08:00
[[ClientConfig shareConfig] clientInit];
}
- (void)toLoginPage {
2025-03-14 19:43:04 +08:00
LoginViewController *lvc = [[LoginViewController alloc] init];
BaseNavigationController * navigationController = [[BaseNavigationController alloc] initWithRootViewController:lvc];
navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
self.window.rootViewController = navigationController;
}
- (void)toHomeTabbarPage {
TabbarViewController *vc = [[TabbarViewController alloc] init];
BaseNavigationController *navigationController = [[BaseNavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = navigationController;
2023-07-06 16:54:13 +08:00
}
- (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene
Restore:(void (^)(BOOL, RestoreStyle))restoreHandler {
2024-03-25 14:39:36 +08:00
NSString *inviteCode = scene.params[@"inviteCode"];
if (inviteCode != nil && [[AccountInfoStorage instance]getUid].length == 0){
ClientConfig *config = [ClientConfig shareConfig];
config.inviteCode = inviteCode;
}
2024-03-20 19:55:26 +08:00
restoreHandler(YES, MLDefault);
}
2023-09-22 17:43:21 +08:00
2023-07-06 16:54:13 +08:00
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSInteger count = [NIMSDK sharedSDK].conversationManager.allUnreadCount;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
}
2023-08-16 14:21:58 +08:00
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self getAdvertisingTrackingAuthority];
2024-05-31 19:56:25 +08:00
[[NSNotificationCenter defaultCenter]postNotificationName:@"kAppDidBecomeActive" object:nil];
2023-08-16 14:21:58 +08:00
}
2023-08-16 14:21:58 +08:00
- (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:
2025-04-02 11:04:07 +08:00
// NSLog(@"用户拒绝IDFA");
2023-08-16 14:21:58 +08:00
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
2025-04-02 11:04:07 +08:00
// NSLog(@"用户允许IDFA");
2023-08-16 14:21:58 +08:00
break;
case ATTrackingManagerAuthorizationStatusNotDetermined: {
2025-04-02 11:04:07 +08:00
// NSLog(@"用户未做选择或未弹窗IDFA");
2023-08-16 14:21:58 +08:00
//1app
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
2025-04-02 11:04:07 +08:00
// NSLog(@"app追踪IDFA权限%lu",(unsigned long)status);
2023-08-16 14:21:58 +08:00
}];
}
break;
default:
break;
}
}
});
}
2023-07-06 16:54:13 +08:00
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
2023-07-14 18:50:55 +08:00
// devicetoken
2024-02-21 10:18:59 +08:00
[[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;
2024-02-21 10:18:59 +08:00
});
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){
2024-02-27 10:40:48 +08:00
[[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"type":@"kOpenChat",@"uid":userId,@"isNoAttention":@(YES)}];
2024-02-21 10:18:59 +08:00
ClientConfig *config = [ClientConfig shareConfig];
config.pushChatId = userId;
2024-02-21 10:18:59 +08:00
}
});
2023-07-06 16:54:13 +08:00
}
2023-08-11 14:46:56 +08:00
///URL Scheme
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
2025-03-21 16:19:07 +08:00
[[SocialShareManager sharedManager] handleURL:url];
2023-08-11 14:46:56 +08:00
2023-09-22 20:23:33 +08:00
return [GIDSignIn.sharedInstance handleURL:url];
2023-08-11 14:46:56 +08:00
}
2025-03-21 16:19:07 +08:00
//- (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;
// }
// }
//}
2023-07-06 16:54:13 +08:00
#pragma mark - Core Data stack
@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
2023-07-14 18:50:55 +08:00
-(NSURL *)applicationDocumentsDirectory{
2023-07-06 16:54:13 +08:00
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
- (NSManagedObjectModel *)managedObjectModel {
2023-07-14 18:50:55 +08:00
// The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
2023-07-06 16:54:13 +08:00
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"_1_______" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
2023-07-14 18:50:55 +08:00
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it.
2023-07-06 16:54:13 +08:00
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
2023-07-14 18:50:55 +08:00
// Create the coordinator and store
2023-07-06 16:54:13 +08:00
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
2023-07-14 18:50:55 +08:00
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"_1_______.sqlite"];
2023-07-06 16:54:13 +08:00
NSError *error = nil;
NSString *failureReason = @"There was an error creating or loading the application's saved data.";
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
2023-07-14 18:50:55 +08:00
// Report any error we got.
2023-07-06 16:54:13 +08:00
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
2023-07-14 18:50:55 +08:00
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
2025-04-02 11:04:07 +08:00
// NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
2023-07-06 16:54:13 +08:00
abort();
}
return _persistentStoreCoordinator;
}
- (NSManagedObjectContext *)managedObjectContext {
2023-07-14 18:50:55 +08:00
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
2023-07-06 16:54:13 +08:00
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (!coordinator) {
return nil;
}
_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
return _managedObjectContext;
}
#pragma mark - Core Data Saving support
2023-07-14 18:50:55 +08:00
- (void)saveContext {
2023-07-06 16:54:13 +08:00
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
NSError *error = nil;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
2023-07-14 18:50:55 +08:00
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
2025-04-02 11:04:07 +08:00
// NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
2023-07-06 16:54:13 +08:00
abort();
}
}
}
@end