2021-09-06 18:47:38 +08:00
|
|
|
|
//
|
|
|
|
|
// AppDelegate.m
|
|
|
|
|
// xplan-ios
|
|
|
|
|
//
|
|
|
|
|
// Created by zu on 2021/8/31.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
#import "TabbarViewController.h"
|
2021-09-07 23:05:43 +08:00
|
|
|
|
#import "BaseNavigationController.h"
|
2021-09-13 18:56:16 +08:00
|
|
|
|
#import "AppDelegate+ThirdConfig.h"
|
2021-11-21 23:25:19 +08:00
|
|
|
|
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
2021-12-08 16:43:26 +08:00
|
|
|
|
#import <NIMSDK/NIMSDK.h>
|
2023-03-17 16:35:25 +08:00
|
|
|
|
#import <LinkedME_iOS/LinkedME.h>
|
|
|
|
|
#import "LinkMeModel.h"
|
|
|
|
|
#import "NSObject+MJExtension.h"
|
2021-09-06 18:47:38 +08:00
|
|
|
|
@interface AppDelegate ()
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation AppDelegate
|
|
|
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
|
|
|
TabbarViewController *vc = [[TabbarViewController alloc] init];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
BaseNavigationController *bnc = [[BaseNavigationController alloc] initWithRootViewController:vc];
|
2021-09-06 18:47:38 +08:00
|
|
|
|
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
2021-09-07 23:05:43 +08:00
|
|
|
|
self.window.rootViewController = bnc;
|
2021-09-06 18:47:38 +08:00
|
|
|
|
[self.window makeKeyAndVisible];
|
2022-10-31 12:15:01 +08:00
|
|
|
|
///设置广告页
|
|
|
|
|
[self setupLaunchADView];
|
2021-09-13 18:56:16 +08:00
|
|
|
|
///初始化一些 sdk配置
|
|
|
|
|
[self initThirdConfig];
|
2023-03-17 16:35:25 +08:00
|
|
|
|
LinkedME* linkedme = [LinkedME getInstance];
|
|
|
|
|
[linkedme initSessionWithLaunchOptions:launchOptions automaticallyDisplayDeepLinkController:NO deepLinkHandler:^(NSDictionary* params, NSError* error) {
|
|
|
|
|
if (!error) {
|
|
|
|
|
//防止传递参数出错取不到数据,导致App崩溃这里一定要用try catch
|
|
|
|
|
@try {
|
|
|
|
|
NSLog(@"LinkedME finished init with params = %@",[params description]);
|
|
|
|
|
//获取标题
|
|
|
|
|
NSString *title = [params objectForKey:@"$og_title"];
|
|
|
|
|
NSString * H5URL;
|
|
|
|
|
NSDictionary *control = params[@"$control"];
|
|
|
|
|
if (![params[@"h5_url"] isEqualToString:@""]) {
|
|
|
|
|
NSString *channel = params[@"h5_url"];
|
|
|
|
|
H5URL = channel;
|
|
|
|
|
}
|
|
|
|
|
NSString * linkedmeChannel = control[@"linkedmeChannel"];
|
|
|
|
|
if (title.length >0) {
|
|
|
|
|
LinkMeModel *linkme = [LinkMeModel modelWithJSON:control];
|
|
|
|
|
if (linkme.url) {
|
|
|
|
|
H5URL = linkme.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (linkme.type) {
|
|
|
|
|
case LinkedMESkipType_Room:
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case LinkedMESkipType_H5:
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//[自动跳转]使用自动跳转
|
|
|
|
|
//SDK提供的跳转方法
|
|
|
|
|
/**
|
|
|
|
|
* pushViewController : 类名
|
|
|
|
|
* storyBoardID : 需要跳转的页面的storyBoardID
|
|
|
|
|
* animated : 是否开启动画
|
|
|
|
|
* customValue : 传参
|
|
|
|
|
*
|
|
|
|
|
*warning 需要在被跳转页中实现次方法 - (void)configureControlWithData:(NSDictionary *)data;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// [LinkedME pushViewController:title storyBoardID:@"detailView" animated:YES customValue:@{@"tag":tag} completion:^{
|
|
|
|
|
////
|
|
|
|
|
// }];
|
|
|
|
|
|
|
|
|
|
//自定义跳转
|
|
|
|
|
// dvc.openUrl = params[@"$control"][@"ViewId"];
|
|
|
|
|
// [[LinkedME getViewController] showViewController:dvc sender:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} @catch (NSException *exception) {
|
|
|
|
|
|
|
|
|
|
} @finally {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
NSLog(@"LinkedME failed init: %@", error);
|
|
|
|
|
}
|
|
|
|
|
}];
|
2021-09-06 18:47:38 +08:00
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-21 23:25:19 +08:00
|
|
|
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
|
|
|
|
[self getAdvertisingTrackingAuthority];
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 14:08:26 +08:00
|
|
|
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
|
|
|
|
NSInteger count = [NIMSDK sharedSDK].conversationManager.allUnreadCount;
|
|
|
|
|
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:count];
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-21 23:25:19 +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");
|
|
|
|
|
//请求弹出用户授权框,只会在程序运行是弹框1次,除非卸载app重装,通地图、相机等权限弹框一样
|
|
|
|
|
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
|
|
|
|
NSLog(@"app追踪IDFA权限:%lu",(unsigned long)status);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 16:43:26 +08:00
|
|
|
|
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
|
|
|
// 上传devicetoken至云信服务器。
|
|
|
|
|
[[NIMSDK sharedSDK] updateApnsToken:deviceToken];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-09 22:18:42 +08:00
|
|
|
|
#pragma mark - Core Data stack
|
|
|
|
|
@synthesize managedObjectContext = _managedObjectContext;
|
|
|
|
|
@synthesize managedObjectModel = _managedObjectModel;
|
|
|
|
|
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
|
|
|
|
|
|
|
|
|
|
-(NSURL *)applicationDocumentsDirectory{
|
|
|
|
|
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSManagedObjectModel *)managedObjectModel {
|
|
|
|
|
// 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.
|
|
|
|
|
if (_managedObjectModel != nil) {
|
|
|
|
|
return _managedObjectModel;
|
|
|
|
|
}
|
|
|
|
|
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"_1_______" withExtension:@"momd"];
|
|
|
|
|
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
|
|
|
|
|
return _managedObjectModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
|
|
|
|
|
// The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it.
|
|
|
|
|
if (_persistentStoreCoordinator != nil) {
|
|
|
|
|
return _persistentStoreCoordinator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the coordinator and store
|
|
|
|
|
|
|
|
|
|
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
|
|
|
|
|
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"_1_______.sqlite"];
|
|
|
|
|
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]) {
|
|
|
|
|
// Report any error we got.
|
|
|
|
|
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];
|
|
|
|
|
// 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.
|
|
|
|
|
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _persistentStoreCoordinator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSManagedObjectContext *)managedObjectContext {
|
|
|
|
|
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
- (void)saveContext {
|
|
|
|
|
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
|
|
|
|
|
if (managedObjectContext != nil) {
|
|
|
|
|
NSError *error = nil;
|
|
|
|
|
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
|
|
|
|
|
// 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.
|
|
|
|
|
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-17 16:35:25 +08:00
|
|
|
|
#pragma mark 实现深度链接技术
|
|
|
|
|
//URI Scheme 实现深度链接技术
|
|
|
|
|
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
|
|
|
|
|
//判断是否是通过LinkedME的UrlScheme唤起App
|
|
|
|
|
if ([[url description] rangeOfString:@"click_id"].location != NSNotFound) {
|
|
|
|
|
[[LinkedME getInstance] handleDeepLink:url];
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
|
|
|
|
|
//判断是否是通过LinkedME的UrlScheme唤起App
|
|
|
|
|
if ([[url description] rangeOfString:@"click_id"].location != NSNotFound) {
|
|
|
|
|
[[LinkedME getInstance] handleDeepLink:url];
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Universal Links 通用链接实现深度链接技术
|
|
|
|
|
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
|
|
|
|
|
//判断是否是通过LinkedME的Universal Links唤起App
|
|
|
|
|
if ([[userActivity.webpageURL description] rangeOfString:@"lkme.cc"].location != NSNotFound) {
|
|
|
|
|
[[LinkedME getInstance] continueUserActivity:userActivity];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-09 22:18:42 +08:00
|
|
|
|
|
2021-09-06 18:47:38 +08:00
|
|
|
|
@end
|