258 lines
8.6 KiB
Objective-C
258 lines
8.6 KiB
Objective-C
//
|
||
// AppDelegate+ThirdConfig.m
|
||
// YUMI
|
||
//
|
||
// Created by YUMI on 2021/9/13.
|
||
//
|
||
|
||
#import "AppDelegate+ThirdConfig.h"
|
||
///Third
|
||
#import <NIMSDK/NIMSDK.h>
|
||
#import <ShareSDK/ShareSDK.h>
|
||
#import <UserNotifications/UNUserNotificationCenter.h>
|
||
#import <UserNotifications/UserNotifications.h>
|
||
#import <MOBFoundation/MobSDK+Privacy.h>
|
||
///Tool
|
||
#import "YUMIConstant.h"
|
||
#import "CustomAttachmentDecoder.h"
|
||
#import "QEmotionHelper.h"
|
||
#import "XPAdvertiseView.h"
|
||
#import "XPAdImageTool.h"
|
||
#import "YUMIMacroUitls.h"
|
||
#import "AdvertiseModel.h"
|
||
#import "XPWebViewController.h"
|
||
#import "XPRoomViewController.h"
|
||
#import "XCCurrentVCStackManager.h"
|
||
#import "ClientConfig.h"
|
||
#import <Adjust/Adjust.h>
|
||
#import <UserNotifications/UserNotifications.h>
|
||
|
||
#import <Bugly/Bugly.h>
|
||
|
||
#import "YuMi-swift.h"
|
||
|
||
UIKIT_EXTERN NSString * kYouMiNumberCountKey;
|
||
UIKIT_EXTERN NSString * adImageName;
|
||
|
||
@implementation AppDelegate (ThirdConfig)
|
||
|
||
/// 初始化一些第三方配置
|
||
- (void)initThirdConfig{
|
||
[self setLanguage];
|
||
[self configShareSDK];
|
||
[self configNIMSDK];
|
||
[self configAdjust];
|
||
[self configBugly];
|
||
[self registerNot];
|
||
[self initEmojiData];
|
||
}
|
||
|
||
-(void)setLanguage{
|
||
UISemanticContentAttribute attribute = UISemanticContentAttributeForceLeftToRight;
|
||
if (isMSRTL()) {
|
||
attribute = UISemanticContentAttributeForceRightToLeft;
|
||
}
|
||
|
||
[UIView appearance].semanticContentAttribute = attribute;
|
||
[UISearchBar appearance].semanticContentAttribute = attribute;
|
||
}
|
||
|
||
-(void)registerNot{
|
||
if (@available(iOS 10.0, *)) {
|
||
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
||
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
||
if (granted) {
|
||
[center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
|
||
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized){
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
||
});
|
||
}
|
||
}];
|
||
}
|
||
}];
|
||
}
|
||
}
|
||
|
||
/**
|
||
崩溃收集 Bugly
|
||
*/
|
||
- (void) configBugly {
|
||
|
||
BuglyConfig *config = [[BuglyConfig alloc] init];
|
||
|
||
config.blockMonitorTimeout = 5;
|
||
config.unexpectedTerminatingDetectionEnable = YES; // 非正常退出事件记录开关,默认关闭
|
||
|
||
#ifdef DEBUG
|
||
config.debugMode = NO;//YES; // debug 模式下,开启调试模式
|
||
config.channel = [YYUtility getAppSource];
|
||
// config.blockMonitorEnable = YES; // 卡顿监控开关,默认关闭
|
||
config.reportLogLevel = BuglyLogLevelError; // BuglyLogLevelVerbose; // 设置打印日志级别
|
||
[Bugly startWithAppId:@"c937fd00f7" config:config];
|
||
#else
|
||
config.debugMode = NO; // release 模式下,关闭调试模式
|
||
config.channel = [YYUtility getAppSource];;
|
||
config.blockMonitorEnable = NO; // 卡顿监控开关,默认关闭
|
||
config.reportLogLevel = BuglyLogLevelWarn; // 设置自定义日志上报的级别,默认不上报自定义日志
|
||
NSString *buylyKey = @"8627948559"; // isEnterprise == NO ? @"5334684d86" : @"d65df59a68";
|
||
[Bugly startWithAppId:buylyKey config:config];
|
||
#endif
|
||
|
||
}
|
||
- (void)configNIMSDK {
|
||
//推荐在程序启动的时候初始化 NIMSDK
|
||
NSString *appKey = KeyWithType(KeyType_NetEase);
|
||
NIMSDKOption *option = [NIMSDKOption optionWithAppKey:appKey];
|
||
#ifdef DEBUG
|
||
option.apnsCername = @"pikoDevelopPush";
|
||
#else
|
||
option.apnsCername = @"newPiko";
|
||
#endif
|
||
|
||
[[NIMSDK sharedSDK] registerWithOption:option];
|
||
|
||
// NIM SDK初始化
|
||
[NIMCustomObject registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
|
||
[NIMSDKConfig sharedConfig].shouldConsiderRevokedMessageUnreadCount = YES;
|
||
///置顶会话同步
|
||
[[NIMSDKConfig sharedConfig] setShouldSyncStickTopSessionInfos:YES];
|
||
#ifdef DEBUG
|
||
[NIMSDKConfig sharedConfig].enabledHttpsForInfo = NO;
|
||
[NIMSDKConfig sharedConfig].enabledHttpsForMessage = NO;
|
||
#endif
|
||
}
|
||
|
||
-(void)configAdjust{
|
||
NSString *appToken = @"p5sndfu9udq8";
|
||
NSString *environment;
|
||
#ifdef DEBUG
|
||
environment = ADJEnvironmentSandbox;
|
||
#else
|
||
environment = ADJEnvironmentProduction;
|
||
#endif
|
||
|
||
ADJConfig*adjustConfig = [ADJConfig configWithAppToken:appToken
|
||
environment:environment];
|
||
|
||
#ifdef DEBUG
|
||
[adjustConfig setLogLevel:ADJLogLevelVerbose];
|
||
#else
|
||
|
||
#endif
|
||
[Adjust appDidLaunch:adjustConfig];
|
||
}
|
||
|
||
- (void)configShareSDK {
|
||
|
||
[PILineLoginManager registerLine];
|
||
|
||
[ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
|
||
///faceBook
|
||
// [platformsRegister setupFacebookWithAppkey:@"1266232494209868" appSecret:@"c9b170b383f8be9cdf118823b8632821" displayName:YMLocalizedString(@"AppDelegate_ThirdConfig0")];
|
||
[platformsRegister setupLineAuthType:SSDKAuthorizeTypeBoth];
|
||
}];
|
||
|
||
NSString *isUpload = [[NSUserDefaults standardUserDefaults]valueForKey:@"kMobLinkUploadPrivacy"];
|
||
if (isUpload == nil){
|
||
[MobSDK uploadPrivacyPermissionStatus:YES onResult:nil];
|
||
[[NSUserDefaults standardUserDefaults] setValue:@"YES" forKey:@"kMobLinkUploadPrivacy"];
|
||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
}
|
||
}
|
||
|
||
#pragma mark - 表情
|
||
- (void)initEmojiData {
|
||
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
||
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;
|
||
});
|
||
}
|
||
|
||
#pragma mark - 广告
|
||
|
||
/**
|
||
设置广告页
|
||
*/
|
||
- (void)setupLaunchADView {
|
||
NSUserDefaults * kUserDefaults = NSUserDefaults.standardUserDefaults;
|
||
// 判断沙盒中是否存在广告图片,如果存在,直接显示
|
||
NSString *adName = [kUserDefaults stringForKey:adImageName];
|
||
NSString *filePath = [XPAdImageTool.shareImageTool getFilePathWithImageName:adName];
|
||
BOOL isExist = [XPAdImageTool.shareImageTool isFileExistWithFilePath:filePath];
|
||
|
||
if ([kUserDefaults integerForKey:@"adShow"]) {
|
||
[kUserDefaults setInteger:[kUserDefaults integerForKey:@"adShow"]+1
|
||
forKey:@"adShow"];
|
||
} else {
|
||
[kUserDefaults setInteger:1 forKey:@"adShow"];
|
||
}
|
||
|
||
if (isExist) {// 图片存在
|
||
if ([kUserDefaults integerForKey:@"adShow"] > 4) {
|
||
@kWeakify(self);
|
||
AdvertiseModel *info = [XPAdImageTool.shareImageTool getAdInfoFromCacheInMainWith:adName];
|
||
XPAdvertiseView *advertiseView = [[XPAdvertiseView alloc] initWithFrame:self.window.bounds];
|
||
advertiseView.filePath = filePath;
|
||
advertiseView.dismissHandler = ^(BOOL shouldJump) {
|
||
@kStrongify(self)
|
||
if (!shouldJump || info == nil) {
|
||
return;
|
||
}
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||
[self advertiseJumpHandleWithInfo:info];
|
||
});
|
||
};
|
||
[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;
|
||
}
|
||
}
|
||
@end
|