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

301 lines
12 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>
#import <FBSDKCoreKit/FBSDKCoreKit.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 "GULAppDelegateSwizzler.h"
#import <GoogleSignIn/GoogleSignIn.h>
2023-10-07 18:42:30 +08:00
#import "XPLoginViewController.h"
#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"
2023-08-08 16:48:02 +08:00
@import Firebase;
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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/// sdk
[self initThirdConfig];
[self initUM:application launchOptions:launchOptions];
2023-07-06 16:54:13 +08:00
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
[self loadMainPage];
[self setupLaunchADView];
return YES;
}
- (void)initUM:(UIApplication *)application
launchOptions:(NSDictionary *)launchOptions {
//
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kYouMinumbernnagna"]) {
///
[UMConfigure initWithAppkey:@"6434c6dfd64e686139618269"
channel:@"appstore"];
}
2023-08-11 14:46:56 +08:00
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
2023-08-08 16:48:02 +08:00
[FIRApp configure];
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];
}
}
- (void)toLoginPage {
XPLoginViewController *lvc = [[XPLoginViewController 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:
NSLog(@"用户拒绝IDFA");
break;
case ATTrackingManagerAuthorizationStatusAuthorized:
NSLog(@"用户允许IDFA");
break;
case ATTrackingManagerAuthorizationStatusNotDetermined: {
NSLog(@"用户未做选择或未弹窗IDFA");
//1app
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
NSLog(@"app追踪IDFA权限%lu",(unsigned long)status);
}];
}
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{
2023-12-29 16:43:37 +08:00
NSString *bundleID = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
if ([url.scheme isEqualToString:[NSString stringWithFormat:@"line3rdp.%@",bundleID]]) {
return [PILineLoginManager applicationOpenurl:app open:url];
}
2023-08-11 14:46:56 +08:00
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}];
2023-08-17 18:26:13 +08:00
ClientConfig *config = [ClientConfig shareConfig];
config.roomId = uid;
2023-08-25 16:32:51 +08:00
}else if(type == 7){
2023-08-18 10:41:30 +08:00
NSString *uid = [NSString stringWithFormat:@"%@",paramsDict[@"uid"]];
[[NSNotificationCenter defaultCenter]postNotificationName:kOpenRoomNotification object:nil userInfo:@{@"type":@"kOpenChat",@"uid":uid}];
ClientConfig *config = [ClientConfig shareConfig];
config.chatId = uid;
2024-03-19 14:48:45 +08:00
}else if (type == 8){
NSString *inviteCode = paramsDict[@"inviteCode"];
if (inviteCode != nil && [[AccountInfoStorage instance]getUid].length == 0){
2024-03-20 19:55:26 +08:00
ClientConfig *config = [ClientConfig shareConfig];
config.inviteCode = inviteCode;
2024-03-19 14:48:45 +08:00
}
2023-08-11 14:46:56 +08:00
}
return YES;
}
2023-08-17 16:10:11 +08:00
2023-08-11 14:46:56 +08:00
}
2023-09-22 20:23:33 +08:00
if([url.absoluteString containsString:@"fb1266232494209868"]){
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
return [GIDSignIn.sharedInstance handleURL:url];
2023-08-11 14:46:56 +08:00
}
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.
2023-07-06 16:54:13 +08:00
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
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.
2023-07-06 16:54:13 +08:00
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
@end