项目优化:

1. 优化代码格式
2. 优化冷启动时第三方的加载顺序
This commit is contained in:
eggmanQQQ
2024-06-12 11:23:10 +08:00
parent 2469e186b4
commit 0585d1e9e6
2 changed files with 97 additions and 85 deletions

View File

@@ -36,47 +36,42 @@ UIKIT_EXTERN NSString * adImageName;
@implementation AppDelegate (ThirdConfig) @implementation AppDelegate (ThirdConfig)
/// ///
- (void)initThirdConfig { - (void)initThirdConfig{
[self configShareSDK]; [self configShareSDK];
[self configNIMSDK]; [self configNIMSDK];
[self initEmojiData];
[self configAdjust]; [self configAdjust];
[self configBugly]; [self configBugly];
[self registerNot]; [self registerNot];
[self initEmojiData];
[self setLanguage]; [self setLanguage];
} }
-(void)setLanguage{ -(void)setLanguage{
UISemanticContentAttribute attribute = UISemanticContentAttributeForceLeftToRight;
if (isMSRTL()) { if (isMSRTL()) {
[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; attribute = UISemanticContentAttributeForceRightToLeft;
[UISearchBar appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
} else {
[UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
[UISearchBar appearance].semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
} }
[UIView appearance].semanticContentAttribute = attribute;
[UISearchBar appearance].semanticContentAttribute = attribute;
} }
-(void)registerNot{ -(void)registerNot{
if (@available(iOS 10.0, *)) { if (@available(iOS 10.0, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) { [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted) { if (granted) {
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) { [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){ if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications]; [[UIApplication sharedApplication] registerForRemoteNotifications];
}); });
}
}];
} }
}]; }];
} }
}];
}
} }
/** /**
@@ -113,9 +108,6 @@ UIKIT_EXTERN NSString * adImageName;
option.apnsCername = @"newPiko"; option.apnsCername = @"newPiko";
#endif #endif
[[NIMSDK sharedSDK] registerWithOption:option]; [[NIMSDK sharedSDK] registerWithOption:option];
// NIM SDK // NIM SDK
@@ -148,6 +140,7 @@ UIKIT_EXTERN NSString * adImageName;
#endif #endif
[Adjust appDidLaunch:adjustConfig]; [Adjust appDidLaunch:adjustConfig];
} }
- (void)configShareSDK { - (void)configShareSDK {
[PILineLoginManager registerLine]; [PILineLoginManager registerLine];
@@ -157,11 +150,10 @@ UIKIT_EXTERN NSString * adImageName;
// [platformsRegister setupFacebookWithAppkey:@"1266232494209868" appSecret:@"c9b170b383f8be9cdf118823b8632821" displayName:YMLocalizedString(@"AppDelegate_ThirdConfig0")]; // [platformsRegister setupFacebookWithAppkey:@"1266232494209868" appSecret:@"c9b170b383f8be9cdf118823b8632821" displayName:YMLocalizedString(@"AppDelegate_ThirdConfig0")];
[platformsRegister setupLineAuthType:SSDKAuthorizeTypeBoth]; [platformsRegister setupLineAuthType:SSDKAuthorizeTypeBoth];
}]; }];
NSString *isUpload = [[NSUserDefaults standardUserDefaults]valueForKey:@"kMobLinkUploadPrivacy"]; NSString *isUpload = [[NSUserDefaults standardUserDefaults]valueForKey:@"kMobLinkUploadPrivacy"];
if (isUpload == nil){ if (isUpload == nil){
[MobSDK uploadPrivacyPermissionStatus:YES onResult:^(BOOL success) { [MobSDK uploadPrivacyPermissionStatus:YES onResult:nil];
}];
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"kMobLinkUploadPrivacy"]; [[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"kMobLinkUploadPrivacy"];
[[NSUserDefaults standardUserDefaults] synchronize]; [[NSUserDefaults standardUserDefaults] synchronize];
} }
@@ -169,22 +161,24 @@ UIKIT_EXTERN NSString * adImageName;
#pragma mark - #pragma mark -
- (void)initEmojiData { - (void)initEmojiData {
NSArray * dicArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"emoji" ofType:@"plist"]]; dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSDictionary * dic = [dicArray firstObject]; NSArray * dicArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"emoji" ofType:@"plist"]];
NSArray * emojiArray = dic[@"data"]; NSDictionary * dic = [dicArray firstObject];
NSMutableArray * array = [NSMutableArray array]; NSArray * emojiArray = dic[@"data"];
for (int i = 0; i < emojiArray.count; i++) { NSMutableArray * array = [NSMutableArray array];
NSDictionary * dic = [emojiArray objectAtIndex:i]; for (int i = 0; i < emojiArray.count; i++) {
UIImage * image = [UIImage imageNamed:dic[@"file"]]; NSDictionary * dic = [emojiArray objectAtIndex:i];
QEmotion * info = [[QEmotion alloc] init]; UIImage * image = [UIImage imageNamed:dic[@"file"]];
info.identifier = dic[@"id"]; QEmotion * info = [[QEmotion alloc] init];
info.image = image; info.identifier = dic[@"id"];
info.displayName = dic[@"tag"]; info.image = image;
[array addObject:info]; info.displayName = dic[@"tag"];
} [array addObject:info];
// }
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper]; //
faceManager.emotionArray = array; QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
faceManager.emotionArray = array;
});
} }
#pragma mark - 广 #pragma mark - 广
@@ -195,22 +189,21 @@ UIKIT_EXTERN NSString * adImageName;
- (void)setupLaunchADView { - (void)setupLaunchADView {
NSUserDefaults * kUserDefaults = NSUserDefaults.standardUserDefaults; NSUserDefaults * kUserDefaults = NSUserDefaults.standardUserDefaults;
// 广 // 广
NSString *filePath = [XPAdImageTool.shareImageTool getFilePathWithImageName:[kUserDefaults valueForKey:adImageName]]; NSString *adName = [kUserDefaults stringForKey:adImageName];
NSString *filePath = [XPAdImageTool.shareImageTool getFilePathWithImageName:adName];
BOOL isExist = [XPAdImageTool.shareImageTool isFileExistWithFilePath:filePath]; BOOL isExist = [XPAdImageTool.shareImageTool isFileExistWithFilePath:filePath];
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
if ([userDefault integerForKey:@"adShow"]) { if ([kUserDefaults integerForKey:@"adShow"]) {
[userDefault setInteger:[userDefault integerForKey:@"adShow"]+1 forKey:@"adShow"]; [kUserDefaults setInteger:[kUserDefaults integerForKey:@"adShow"]+1
forKey:@"adShow"];
} else { } else {
[userDefault setInteger:1 forKey:@"adShow"]; [kUserDefaults setInteger:1 forKey:@"adShow"];
} }
if (isExist) {// if (isExist) {//
if ([kUserDefaults integerForKey:@"adShow"] > 4) {
if ([userDefault integerForKey:@"adShow"] > 4) {
@kWeakify(self); @kWeakify(self);
NSString *imageName = [kUserDefaults valueForKey:adImageName]; AdvertiseModel *info = [XPAdImageTool.shareImageTool getAdInfoFromCacheInMainWith:adName];
AdvertiseModel *info = [XPAdImageTool.shareImageTool getAdInfoFromCacheInMainWith:imageName];
XPAdvertiseView *advertiseView = [[XPAdvertiseView alloc] initWithFrame:self.window.bounds]; XPAdvertiseView *advertiseView = [[XPAdvertiseView alloc] initWithFrame:self.window.bounds];
advertiseView.filePath = filePath; advertiseView.filePath = filePath;
advertiseView.dismissHandler = ^(BOOL shouldJump) { advertiseView.dismissHandler = ^(BOOL shouldJump) {
@@ -219,9 +212,8 @@ UIKIT_EXTERN NSString * adImageName;
return; return;
} }
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self performSelectorOnMainThread:@selector(advertiseJumpHandleWithInfo:) withObject:info waitUntilDone:NO]; [self advertiseJumpHandleWithInfo:info];
}); });
}; };
[advertiseView show]; [advertiseView show];
} }

View File

@@ -5,15 +5,16 @@
// Created by admin on 2023/3/9. // Created by admin on 2023/3/9.
// //
#import "AppDelegate.h"
#import <UMCommon/UMCommon.h>
#import <MobLinkPro/MobLink.h> #import <MobLinkPro/MobLink.h>
#import <MobLinkPro/MLSDKScene.h> #import <MobLinkPro/MLSDKScene.h>
#import "AppDelegate.h" #import <FBSDKCoreKit/FBSDKCoreKit.h>
#import "TabbarViewController.h" #import "TabbarViewController.h"
#import "BaseNavigationController.h" #import "BaseNavigationController.h"
#import "AppDelegate+ThirdConfig.h" #import "AppDelegate+ThirdConfig.h"
#import <NIMSDK/NIMSDK.h> #import <NIMSDK/NIMSDK.h>
#import <UMCommon/UMCommon.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h> #import <AppTrackingTransparency/AppTrackingTransparency.h>
#import "ClientConfig.h" #import "ClientConfig.h"
#import <GoogleSignIn/GoogleSignIn.h> #import <GoogleSignIn/GoogleSignIn.h>
@@ -35,35 +36,54 @@ UIKIT_EXTERN NSString * const kOpenRoomNotification;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
AccountModel *accountModel = [[AccountInfoStorage instance] getCurrentAccountInfo];
if (accountModel == nil || accountModel.uid == nil || accountModel.access_token == nil) {
XPLoginViewController *lvc = [[XPLoginViewController alloc] init];
BaseNavigationController * nav = [[BaseNavigationController alloc] initWithRootViewController:lvc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
self.window.rootViewController = nav;
}else{
TabbarViewController *vc = [[TabbarViewController alloc] init];
BaseNavigationController *bnc = [[BaseNavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = bnc;
}
[self.window makeKeyAndVisible];
///广
[self setupLaunchADView];
/// sdk /// sdk
[self initThirdConfig]; [self initThirdConfig];
// [self initUM:application launchOptions:launchOptions];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"kYouMinumbernnagna"]) {
/// self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[UMConfigure initWithAppkey:@"6434c6dfd64e686139618269" channel:@"appstore"]; [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"];
}
[[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
[FIRApp configure]; [FIRApp configure];
[MobLink setDelegate:self]; [MobLink setDelegate:self];
}
return YES; - (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;
} }
- (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene - (void)IMLSDKWillRestoreScene:(MLSDKScene *)scene