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

206 lines
8.7 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"
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>
#import <UMCommon/UMCommon.h>
2023-08-11 14:46:56 +08:00
#import <FBSDKCoreKit/FBSDKCoreKit.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-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
2023-07-06 16:54:13 +08:00
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2023-07-14 18:50:55 +08:00
TabbarViewController *vc = [[TabbarViewController alloc] init];
BaseNavigationController *bnc = [[BaseNavigationController alloc] initWithRootViewController:vc];
2023-07-06 16:54:13 +08:00
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = bnc;
[self.window makeKeyAndVisible];
2023-07-14 18:50:55 +08:00
///广
[self setupLaunchADView];
/// sdk
[self initThirdConfig];
//
2023-07-06 16:54:13 +08:00
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kYouMinumbernnagna"]) {
2023-07-14 18:50:55 +08:00
///
2023-07-06 16:54:13 +08:00
[UMConfigure initWithAppkey:@"6434c6dfd64e686139618269" channel:@"yumi_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];
2023-07-06 16:54:13 +08:00
return YES;
}
- (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];
}
- (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
2023-07-06 16:54:13 +08:00
[[NIMSDK sharedSDK] updateApnsToken:deviceToken];
}
2023-08-11 14:46:56 +08:00
///URL Scheme
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options{
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;
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
}
return [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
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