2021-09-13 18:56:16 +08:00
|
|
|
|
//
|
|
|
|
|
// AppDelegate+ThirdConfig.m
|
|
|
|
|
// xplan-ios
|
|
|
|
|
//
|
|
|
|
|
// Created by 冯硕 on 2021/9/13.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "AppDelegate+ThirdConfig.h"
|
|
|
|
|
///Third
|
|
|
|
|
#import <ShareSDK/ShareSDK.h>
|
2021-10-21 12:01:21 +08:00
|
|
|
|
#import <NIMSDK/NIMSDK.h>
|
2021-12-06 17:31:52 +08:00
|
|
|
|
#import <UMCommon/UMCommon.h>
|
2021-12-08 16:43:26 +08:00
|
|
|
|
#import <UserNotifications/UNUserNotificationCenter.h>
|
2022-10-17 17:54:04 +08:00
|
|
|
|
#import <Bugly/Bugly.h>
|
2021-09-13 18:56:16 +08:00
|
|
|
|
///Tool
|
|
|
|
|
#import "XPConstant.h"
|
2021-11-16 19:56:37 +08:00
|
|
|
|
#import "CustomAttachmentDecoder.h"
|
2022-08-17 18:55:45 +08:00
|
|
|
|
#import "QEmotionHelper.h"
|
2022-10-31 12:15:01 +08:00
|
|
|
|
#import "XPAdvertiseView.h"
|
|
|
|
|
#import "XPAdImageTool.h"
|
|
|
|
|
#import "XPMacro.h"
|
|
|
|
|
#import "AdvertiseModel.h"
|
|
|
|
|
#import "XPWebViewController.h"
|
|
|
|
|
#import "XPRoomViewController.h"
|
|
|
|
|
#import "XCCurrentVCStackManager.h"
|
2021-09-13 18:56:16 +08:00
|
|
|
|
|
2021-12-06 17:31:52 +08:00
|
|
|
|
UIKIT_EXTERN NSString * kYinyouPrivateKey;
|
2022-10-31 12:15:01 +08:00
|
|
|
|
UIKIT_EXTERN NSString * adImageName;
|
2021-12-06 17:31:52 +08:00
|
|
|
|
|
2021-09-13 18:56:16 +08:00
|
|
|
|
@implementation AppDelegate (ThirdConfig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 初始化一些第三方配置
|
|
|
|
|
- (void)initThirdConfig {
|
|
|
|
|
[self configShareSDK];
|
2021-10-21 12:01:21 +08:00
|
|
|
|
[self configNIMSDK];
|
2021-12-06 17:31:52 +08:00
|
|
|
|
[self configUMengSDK];
|
2022-08-17 18:55:45 +08:00
|
|
|
|
[self initEmojiData];
|
2022-10-17 17:54:04 +08:00
|
|
|
|
[self configBugly];
|
2021-09-13 18:56:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)configShareSDK {
|
|
|
|
|
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
|
|
|
|
|
//QQ
|
2022-09-23 18:12:28 +08:00
|
|
|
|
NSString *universalLink = @"https://a6lno.share2dlink.com/";
|
|
|
|
|
NSString *qqUniversalLink = @"https://a6lno.share2dlink.com/qq_conn/101902443";
|
|
|
|
|
[platformsRegister setupQQWithAppId:KeyWithType(KeyType_QQAppid) appkey:KeyWithType(KeyType_QQSecret) enableUniversalLink:YES universalLink:qqUniversalLink];
|
|
|
|
|
[platformsRegister setupWeChatWithAppId:KeyWithType(KeyType_WechatAppid) appSecret:KeyWithType(KeyType_WechatSecret) universalLink:universalLink];
|
|
|
|
|
}];
|
2021-09-13 18:56:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 12:01:21 +08:00
|
|
|
|
- (void)configNIMSDK {
|
|
|
|
|
//推荐在程序启动的时候初始化 NIMSDK
|
|
|
|
|
NSString *appKey = KeyWithType(KeyType_NetEase);
|
|
|
|
|
NIMSDKOption *option = [NIMSDKOption optionWithAppKey:appKey];
|
|
|
|
|
option.apnsCername = KeyWithType(KeyType_APNSCer);
|
|
|
|
|
[[NIMSDK sharedSDK] registerWithOption:option];
|
2021-11-16 19:56:37 +08:00
|
|
|
|
|
|
|
|
|
// NIM SDK初始化
|
2021-11-26 20:25:23 +08:00
|
|
|
|
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
[NIMSDKConfig sharedConfig].enabledHttpsForInfo = NO;
|
|
|
|
|
[NIMSDKConfig sharedConfig].enabledHttpsForMessage = NO;
|
|
|
|
|
#endif
|
2021-12-08 16:43:26 +08:00
|
|
|
|
|
|
|
|
|
if (@available(iOS 11.0, *)){
|
|
|
|
|
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
|
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
2021-10-21 12:01:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 17:54:04 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
崩溃收集 Bugly
|
|
|
|
|
*/
|
|
|
|
|
- (void) configBugly {
|
|
|
|
|
|
|
|
|
|
BuglyConfig *config = [[BuglyConfig alloc] init];
|
|
|
|
|
config.channel = @"App Enterprise";
|
|
|
|
|
config.blockMonitorEnable = YES; // 卡顿监控开关,默认关闭
|
|
|
|
|
config.blockMonitorTimeout = 5;
|
|
|
|
|
config.unexpectedTerminatingDetectionEnable = YES; // 非正常退出事件记录开关,默认关闭
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
config.debugMode = YES; // debug 模式下,开启调试模式
|
2022-11-10 12:11:25 +08:00
|
|
|
|
config.reportLogLevel = BuglyLogLevelWarn; // 设置自定义日志上报的级别,默认不上报自定义日志
|
2022-11-01 17:10:13 +08:00
|
|
|
|
[Bugly startWithAppId:KeyWithType(KeyTyoe_BuglyKey) config:config];
|
2022-10-17 17:54:04 +08:00
|
|
|
|
#else
|
|
|
|
|
config.debugMode = NO; // release 模式下,关闭调试模式
|
|
|
|
|
config.reportLogLevel = BuglyLogLevelWarn; // 设置自定义日志上报的级别,默认不上报自定义日志
|
2022-11-01 17:10:13 +08:00
|
|
|
|
[Bugly startWithAppId:KeyWithType(KeyTyoe_BuglyKey) config:config];
|
2022-10-17 17:54:04 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 17:31:52 +08:00
|
|
|
|
#pragma mark - 友盟SDK
|
|
|
|
|
- (void)configUMengSDK {
|
|
|
|
|
// 只有同意过了隐私协议 才初始化
|
|
|
|
|
if ([[NSUserDefaults standardUserDefaults] objectForKey:kYinyouPrivateKey]) {
|
|
|
|
|
[UMConfigure initWithAppkey:KeyWithType(keyType_UMengAppKey) channel:KeyWithType(keyType_UMengAppChannel)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-17 18:55:45 +08:00
|
|
|
|
#pragma mark - 表情
|
|
|
|
|
- (void)initEmojiData {
|
|
|
|
|
NSArray * dicArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"emoji" ofType:@"plist"]];
|
|
|
|
|
NSDictionary * dic = [dicArray firstObject];
|
|
|
|
|
NSArray * emojiArray = dic[@"data"];
|
|
|
|
|
NSMutableArray * array = [NSMutableArray array];
|
|
|
|
|
for (int i = 0; i < emojiArray.count; i++) {
|
|
|
|
|
NSDictionary * dic = [emojiArray objectAtIndex:i];
|
|
|
|
|
UIImage * image = [UIImage imageNamed:dic[@"file"]];
|
|
|
|
|
QEmotion * info = [[QEmotion alloc] init];
|
|
|
|
|
info.identifier = dic[@"id"];
|
|
|
|
|
info.image = image;
|
|
|
|
|
info.displayName = dic[@"tag"];
|
|
|
|
|
[array addObject:info];
|
|
|
|
|
}
|
|
|
|
|
//在这里强烈建议先预加载一下表情
|
|
|
|
|
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
|
|
|
|
faceManager.emotionArray = array;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-31 12:15:01 +08:00
|
|
|
|
#pragma mark - 广告
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
设置广告页
|
|
|
|
|
*/
|
|
|
|
|
- (void)setupLaunchADView {
|
|
|
|
|
NSUserDefaults * kUserDefaults = NSUserDefaults.standardUserDefaults;
|
|
|
|
|
// 判断沙盒中是否存在广告图片,如果存在,直接显示
|
|
|
|
|
NSString *filePath = [XPAdImageTool.shareImageTool getFilePathWithImageName:[kUserDefaults valueForKey:adImageName]];
|
|
|
|
|
BOOL isExist = [XPAdImageTool.shareImageTool isFileExistWithFilePath:filePath];
|
|
|
|
|
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
|
|
if ([userDefault integerForKey:@"adShow"]) {
|
|
|
|
|
[userDefault setInteger:[userDefault integerForKey:@"adShow"]+1 forKey:@"adShow"];
|
|
|
|
|
} else {
|
|
|
|
|
[userDefault setInteger:1 forKey:@"adShow"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isExist) {// 图片存在
|
|
|
|
|
|
|
|
|
|
if ([userDefault integerForKey:@"adShow"] > 4) {
|
|
|
|
|
@kWeakify(self);
|
|
|
|
|
NSString *imageName = [kUserDefaults valueForKey:adImageName];
|
|
|
|
|
AdvertiseModel *info = [XPAdImageTool.shareImageTool getAdInfoFromCacheInMainWith:imageName];
|
|
|
|
|
XPAdvertiseView *advertiseView = [[XPAdvertiseView alloc] initWithFrame:self.window.bounds];
|
|
|
|
|
advertiseView.filePath = filePath;
|
|
|
|
|
advertiseView.dismissHandler = ^(BOOL shouldJump) {
|
|
|
|
|
@kStrongify(self)
|
|
|
|
|
if (!shouldJump || info == nil) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
[self performSelectorOnMainThread:@selector(advertiseJumpHandleWithInfo:) withObject:info waitUntilDone:NO];
|
|
|
|
|
};
|
|
|
|
|
[advertiseView show];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// 闪屏广告跳转处理
|
|
|
|
|
- (void)advertiseJumpHandleWithInfo:(AdvertiseModel *)info {
|
|
|
|
|
if (UIApplication.sharedApplication.keyWindow != self.window) {
|
|
|
|
|
//当前窗口不是主控制器所在窗口时,拦截跳转(目前可能情况时,闪屏后出现新人引导
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (info.type) {
|
|
|
|
|
case SplashInfoSkipTypeRoom: {
|
|
|
|
|
if (![[XPAdImageTool shareImageTool] isImLogin]) {
|
|
|
|
|
return; // 必须登录后才可以跳转
|
|
|
|
|
}
|
|
|
|
|
// 跳转房间
|
|
|
|
|
if (info.link.length > 0) {
|
|
|
|
|
[XPRoomViewController openRoom:info.link viewController:[XCCurrentVCStackManager shareManager].getCurrentVC];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SplashInfoSkipTypeWeb: {
|
|
|
|
|
// 跳转 H5
|
|
|
|
|
if (info.link.length > 0) {
|
|
|
|
|
XPWebViewController *webView = [[XPWebViewController alloc]init];
|
|
|
|
|
webView.url = info.link;
|
|
|
|
|
[[[XCCurrentVCStackManager shareManager]currentNavigationController] pushViewController:webView animated:YES];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-13 18:56:16 +08:00
|
|
|
|
@end
|