123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- //
- // AppDelegate.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/16.
- //
- #import "AppDelegate.h"
- #import <AppTrackingTransparency/AppTrackingTransparency.h>
- #import "KSUpdateManager.h"
- #import "KSUpdateAlert.h"
- #import "KSNetworkAccessibleManager.h"
- #import <Bugly/Bugly.h>
- #import <RongIMLib/RongIMLib.h>
- #import <RongIMKit/RongIMKit.h>
- #import <UMCommon/UMCommon.h>
- // 引入 JPush 功能所需头文件
- #import "JPUSHService.h"
- // iOS10 注册 APNs 所需头文件
- #ifdef NSFoundationVersionNumber_iOS_9_x_Max
- #import <UserNotifications/UserNotifications.h>
- #endif
- #import "UrlDecode.h"
- #import "KSBaseWKWebViewController.h"
- #import "UserInfoManager.h"
- #import "KSIMService.h"
- #import "RCConnectionManager.h"
- #import "KSRCIMDataSource.h"
- #import "WXApi.h"
- @interface RCNaviDataInfo : NSObject
- @property (nonatomic, assign) NSTimeInterval uploadVideoDurationLimit;
- @end
- @interface RCNaviDataManager : NSObject
- @property (nonatomic, strong) RCNaviDataInfo *naviData;
- + (instancetype)sharedInstance;
- @end
- @interface AppDelegate ()<UITabBarControllerDelegate,RCIMReceiveMessageDelegate,WXApiDelegate>
- @property (nonatomic, assign) BOOL isNeedUpdate;
- @property (nonatomic, strong) NSTimer *timer;
- @property (nonatomic, strong) KSUpdateAlert *alertView;
- @property (nonatomic, strong) NSMutableDictionary *messageDict;
- @property (nonatomic, assign) BOOL hasCheckTrackAuth;
- @end
- @implementation AppDelegate
- //此方法会在设备横竖屏变化的时候调用
- - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
- if (_allowAutoRotate) {
- //只支持横屏
- return UIInterfaceOrientationMaskLandscapeRight;
- }else{
- //支持竖屏
- return UIInterfaceOrientationMaskPortrait;
- }
- }
- - (void)networkEnableCheck {
- [KSNetworkAccessibleManager setAlertEnable:YES];
- [KSNetworkAccessibleManager setStateDidUpdateNotifier:^(KSNetworkAccessibleState state) {
- NSLog(@"setStateDidUpdateNotifier > %zd", state);
- }];
-
- [KSNetworkAccessibleManager start];
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- [self networkEnableCheck];
- [self registerSDK];
- [Bugly startWithAppId:@"9c0fc0b6b7"];
-
- if (@available(iOS 13.0, *)) {
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
- } else {
- // Fallback on earlier versions
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- }
-
- [[UITabBar appearance] setTranslucent:NO];
- // 全局配置光标颜色
- [[UITextField appearance] setTintColor:THEMECOLOR];
- [[UITextView appearance] setTintColor:THEMECOLOR];
-
- // 配置极光推送
- [self configJPUSHWithLaunchOptions:launchOptions];
- // 融云相关配置
- [self configIM];
-
- NSString *token = UserDefault(TokenKey);
- if ([NSString isEmptyString:token]) { // 未登录
- LoginViewController *logonVC = [[LoginViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:logonVC];
- self.window.rootViewController = navCtrl;
- }
- else {
- [KSNetworkingManager configRequestHeader];
- [USER_MANAGER queryUserInfoConnectRongCloud:YES];
- [self initTableBar];
- self.window.rootViewController=_tabBarController;
- }
- [self.window makeKeyAndVisible];
-
- if (@available(iOS 15.0, *)) {
- UITableView.appearance.sectionHeaderTopPadding = 0;
- }
- if (IOS11) {
- UITableView.appearance.estimatedRowHeight = 0;
- UITableView.appearance.estimatedSectionFooterHeight = 0;
- UITableView.appearance.estimatedSectionHeaderHeight = 0;
-
- } else {
-
- }
- // keyboardManager
- [IQKeyboardManager sharedManager].enable = YES;
- [IQKeyboardManager sharedManager].toolbarManageBehaviour = IQAutoToolbarByPosition;
- [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
- [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 10.0f;
- [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
-
- /**
- * 推送处理 1
- */
- [self registerRemoteNotification:application];
-
-
- [self versionCheck];
-
- if(@available(iOS 11.0, *)){
-
- [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[UIDocumentBrowserViewController class]]].tintColor = THEMECOLOR;
- }
- return YES;
- }
- - (void)registerSDK {
- [WXApi registerApp:@"wx149a928c415c137a" universalLink:@"https://dev.colexiu.com/studentApp/"];
- }
- - (void)appTrackActionAuth {
- if (self.hasCheckTrackAuth == NO) {
- if (@available(iOS 14, *)) {
- [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
- [self configUM];
- }];
- } else {
- // Fallback on earlier versions
- [self configUM];
- }
- self.hasCheckTrackAuth = YES;
- }
- }
- - (void)configUM {
- [UMConfigure initWithAppkey:@"5e6f6458978eea0774044b88" channel:@"App Store"];
- }
- - (void)versionCheck {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [KSUpdateManager ks_updateWithAPPID:@"1487057217" withBundleId:nil block:^(NSString * _Nonnull currentVersion, NSString * _Nonnull storeVersion, NSString * _Nonnull openUrl, BOOL isUpdate) {
- if (isUpdate) {
-
- [KSNetworkingManager appVersionInfoRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
-
- NSString *serviceVersion = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"version"];
- if ([serviceVersion isEqualToString:storeVersion] || [self isLowerVersionCompareLocalVersion:currentVersion serviceVersion:serviceVersion]) {
- // desc
- NSString *descMessage = [[dic dictionaryValueForKey:@"data"] stringValueForKey:@"description"];
- // 判断
- if ([[dic dictionaryValueForKey:@"data"] boolValueForKey:@"isForceUpdate"]) {
- self.isNeedUpdate = YES;
- [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:YES openUrl:openUrl];
- }
- else {
- self.isNeedUpdate = NO;
- [self showAlertWithMemo:storeVersion descMessage:descMessage isforce:NO openUrl:openUrl];
- }
- }
-
- }
- } faliure:^(NSError * _Nonnull error) {
- [self showAlertWithMemo:storeVersion descMessage:@"全新版本上线了,赶快来体验吧!" isforce:NO openUrl:openUrl];
- }];
- }
- else {
- NSLog(@"当前版本%@,商店版本%@,不需要更新",currentVersion,storeVersion);
- }
- }];
- });
- }
- /**
- 极光推送
- */
- - (void)configJPUSHWithLaunchOptions:(NSDictionary *)launchOptions {
- // 3.0.0及以后版本注册
- JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
- if (@available(iOS 12.0, *)) {
- entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
- } else {
- entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound;
- }
- if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
- }
- [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
- //如不需要使用IDFA,advertisingIdentifier 可为nil
- [JPUSHService setupWithOption:launchOptions appKey:@"7e0282ca92c12c8c45a93bb3"
- channel:nil
- apsForProduction:JSPUSH_ENVIRONMENT
- advertisingIdentifier:nil];
- }
- - (void)configIM {
- [RCNaviDataManager sharedInstance].naviData.uploadVideoDurationLimit = 480.0f;
- // 6tnym1br6pv07 正式环境key c9kqb3rdc451j test
- [[RCIM sharedRCIM] initWithAppKey:RCIM_KEY];
-
- //IMKit连接状态的监听器
- [[RCIM sharedRCIM] setConnectionStatusDelegate:KSRMLINK];
- //IMKit消息接收的监听器
- [[RCIM sharedRCIM] setReceiveMessageDelegate:self];
- // 信息提供者
- [RCIM sharedRCIM].userInfoDataSource = KSRMDataSource;
- [[RCIM sharedRCIM] setGroupInfoDataSource:KSRMDataSource];
- // 群名片信息提供者
- [[RCIM sharedRCIM] setGroupUserInfoDataSource:KSRMDataSource];
- // 群成员数据源
- [RCIM sharedRCIM].groupMemberDataSource = KSRMDataSource;
-
- //开启消息@功能(只支持群聊和讨论组, App需要实现群成员数据源groupMemberDataSource)
- RCKitConfigCenter.message.enableMessageMentioned = YES;
- //是否关闭本地通知,默认是打开的
- RCKitConfigCenter.message.disableMessageNotificaiton = NO;
- // 会话界面设置
- RCKitConfigCenter.ui.globalMessageAvatarStyle = RC_USER_AVATAR_RECTANGLE;
- RCKitConfigCenter.ui.globalMessagePortraitSize = CGSizeMake(40, 40);
- // 会话列表头像设置
- RCKitConfigCenter.ui.globalConversationAvatarStyle = RC_USER_AVATAR_RECTANGLE;
- RCKitConfigCenter.ui.globalConversationPortraitSize = CGSizeMake(48, 48);
-
- //开启消息撤回功能
- RCKitConfigCenter.message.enableMessageRecall = YES;
- // 开启消息合并转发
- RCKitConfigCenter.message.enableSendCombineMessage = YES;
- //选择媒体资源时,包含视频文件
- RCKitConfigCenter.message.isMediaSelectorContainVideo = YES;
- //设置显示未注册的消息
- RCKitConfigCenter.message.showUnkownMessage = YES;
-
- //开启发送已读回执
- RCKitConfigCenter.message.enabledReadReceiptConversationTypeList = @[ @(ConversationType_PRIVATE), @(ConversationType_GROUP)];
-
- //开启输入状态监听
- RCKitConfigCenter.message.enableTypingStatus = YES;
-
- //开启用户信息和群组信息的持久化
- [RCIM sharedRCIM].enablePersistentUserInfoCache = YES;
- // 关闭所有提示音
- RCKitConfigCenter.message.disableMessageAlertSound = YES;
-
- // 设置断线重连时是否踢出重连设备
- // [[RCIMClient sharedRCIMClient] setReconnectKickEnable:YES];
-
- // 左右上角按钮颜色
- RCKitConfigCenter.ui.globalNavigationBarTintColor = HexRGB(0x000000);
- // 注册消息
- // [[RCIM sharedRCIM] registerMessageType:[KSGroupNoticeMessage class]];
-
- // [[RCIMClient sharedRCIMClient] setLogLevel:RC_Log_Level_Verbose];
- // [self redirectNSlogToDocumentFolder];
-
- }
- #pragma mark - private method
- - (void)registerRemoteNotification:(UIApplication *)application {
- /**
- * 推送说明:
- *
- 我们在知识库里还有推送调试页面加了很多说明,当遇到推送问题时可以去知识库里搜索还有查看推送测试页面的说明。
- *
- 首先必须设置deviceToken,可以搜索本文件关键字“推送处理”。模拟器是无法获取devicetoken,也就没有推送功能。
- *
- 当使用"开发/测试环境"的appkey测试推送时,必须用Development的证书打包,并且在后台上传"开发/测试环境"的推送证书,证书必须是development的。
- 当使用"生产/线上环境"的appkey测试推送时,必须用Distribution的证书打包,并且在后台上传"生产/线上环境"的推送证书,证书必须是distribution的。
- */
- if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
- //注册推送, 用于iOS8以及iOS8之后的系统
- UIUserNotificationSettings *settings = [UIUserNotificationSettings
- settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)
- categories:nil];
- [application registerUserNotificationSettings:settings];
- } else {
- //注册推送,用于iOS8之前的系统
- UIRemoteNotificationType myTypes =
- UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
- [application registerForRemoteNotificationTypes:myTypes];
- }
- }
- /**
- * 推送处理2
- */
- //注册用户通知设置
- - (void)application:(UIApplication *)application
- didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
- [application registerForRemoteNotifications];
- }
- /**
- * 推送处理3
- */
- - (void)application:(UIApplication *)application
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
- // 注册极光deviceToken
- /// Required - 注册 DeviceToken
- [JPUSHService registerDeviceToken:deviceToken];
-
- // 融云
- NSString *token = [self getHexStringForData:deviceToken];
- [[RCIMClient sharedRCIMClient] setDeviceToken:token];
- }
- // Data 转换成 NSString(NSData ——> NSString)
- - (NSString *)getHexStringForData:(NSData *)data {
- NSUInteger len = [data length];
- char *chars = (char *)[data bytes];
- NSMutableString *hexString = [[NSMutableString alloc] init];
- for (NSUInteger i = 0; i < len; i ++) {
- [hexString appendString:[NSString stringWithFormat:@"%0.2hhx", chars[i]]];
- }
- return hexString;
- }
- /**
- * 推送处理4
- * userInfo内容请参考官网文档
- */
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
- /**
- * 统计推送打开率2
- */
- [[RCIMClient sharedRCIMClient] recordRemoteNotificationEvent:userInfo];
- /**
- * 获取融云推送服务扩展字段2
- */
- NSDictionary *pushServiceData = [[RCIMClient sharedRCIMClient] getPushExtraFromRemoteNotification:userInfo];
- if (pushServiceData) {
- NSLog(@"该远程推送包含来自融云的推送服务");
- for (id key in [pushServiceData allKeys]) {
- NSLog(@"key = %@, value = %@", key, pushServiceData[key]);
- }
- } else {
- NSLog(@"该远程推送不包含来自融云的推送服务");
- // 极光推送
- [JPUSHService handleRemoteNotification:userInfo];
- }
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- // 后台情况下如果持续时间超过3分钟,主动退出房间
- self.timer = [NSTimer scheduledTimerWithTimeInterval:180.0f target:self selector:@selector(quitClassRoom) userInfo:nil repeats:NO];
- [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
-
- // 退到后台发送消息
- [[NSNotificationCenter defaultCenter] postNotificationName:@"appEnterBackground" object:nil];
- }
- - (void)quitClassRoom {
- [[NSNotificationCenter defaultCenter] postNotificationName:@"backgroundQuit" object:nil];
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application {
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
- if (self.timer) {
- [self.timer invalidate];
- self.timer = nil;
- }
- if (self.isNeedUpdate) {
- [self versionCheck];
- }
- RCConnectionStatus status = [[RCIMClient sharedRCIMClient] getConnectionStatus];
- if (status == ConnectionStatus_Unconnected) { // 连接失败或未连接 需要重新连接
- NSString *token = UserDefault(TokenKey);
- if (![NSString isEmptyString:token]) {
- [USER_MANAGER checkTokenEnableConnectRongCloud];
- }
- }
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application {
- // app启动或者app从后台进入前台都会调用这个方法
- }
- - (void)applicationWillTerminate:(UIApplication *)application {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
- - (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left {
-
- NSLog(@"conversationType----%lu",(unsigned long)message.conversationType);
- // 此处根据消息类型处理对应信息
- if (message.conversationType == ConversationType_CHATROOM) { // 聊天室类型为直播
- [[KSIMService sharedService] ksOnReceivedChatroom:message left:left object:@""];
- }
- if (![message.targetId containsString:@"S"] && ![message.targetId containsString:@"DAYA"] && ![message.targetId containsString:@"I"]) {
- // 此处对单聊、群聊消息处理
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if ([message.content isMemberOfClass:[RCGroupNotificationMessage class]]) {
- RCGroupNotificationMessage *msg = (RCGroupNotificationMessage *)message.content;
- if ([msg.operation isEqualToString:GroupNotificationMessage_GroupOperationKicked]) {
- // [[RCIMClient sharedRCIMClient] removeConversation:ConversationType_GROUP targetId:message.targetId];
- }
- }
- else {
- int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[
- @(ConversationType_PRIVATE), @(ConversationType_APPSERVICE), @(ConversationType_GROUP),@(ConversationType_SYSTEM)
- ]];
- [UIApplication sharedApplication].applicationIconBadgeNumber = unreadMsgCount;
- if (unreadMsgCount >= 1) {
- [self.tabBarController noteNewsWithIndex:2 count:unreadMsgCount];
- } else {
- [self.tabBarController clearNewsWithIndex:2];
- }
- }
- });
- }
- // 小班课视频聊天
- else {
- [[RCIMClient sharedRCIMClient] clearMessagesUnreadStatus:ConversationType_GROUP targetId:message.targetId];
- [[KSIMService sharedService] ksOnReceived:message left:left object:@""];
- }
- }
- #pragma mark- JPUSHRegisterDelegate
- // iOS 10 Support
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
- // Required
- NSDictionary * userInfo = notification.request.content.userInfo;
- if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
- }
- if (@available(iOS 10.0, *)) {
- // completionHandler(UNNotificationPresentationOptionAlert);
- completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound);
- } else {
- // Fallback on earlier versions
- } // 需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置
- }
- // iOS 10 Support
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
- // Required
- NSDictionary * userInfo = response.notification.request.content.userInfo;
- if (@available(iOS 10.0, *)) {
- if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
- }
- } else {
- // Fallback on earlier versions
- }
- completionHandler(); // 系统要求执行这个方法
- NSMutableDictionary *parm = [NSMutableDictionary dictionaryWithDictionary:userInfo];
-
- [self getVCUserInfoDict:parm];
- }
- #pragma mark 根据不同消息跳转不同界面
- - (void)getVCUserInfoDict:(NSMutableDictionary *)infoDict {
-
- }
- - (BOOL)isLowerVersionCompareLocalVersion:(NSString *)localVersion serviceVersion:(NSString *)version {
- localVersion = [localVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
- if (localVersion.length == 3) {
- localVersion = [localVersion stringByAppendingString:@"0"];
- }
- else if (localVersion.length==2) {
- localVersion = [localVersion stringByAppendingString:@"00"];
- }else if (localVersion.length==1){
- localVersion = [localVersion stringByAppendingString:@"000"];
- }
-
- version = [version stringByReplacingOccurrencesOfString:@"." withString:@""];
- if (version.length == 3) {
- version = [version stringByAppendingString:@"0"];
- }
- else if (version.length==2) {
- version = [version stringByAppendingString:@"00"];
- }else if (version.length==1){
- version = [version stringByAppendingString:@"000"];
- }
- if (([localVersion floatValue] < [version floatValue])) {
- return YES;
- }
- else {
- return NO;
- }
- }
- - (void)showMemoAlert {
- if (_isShowFlashAlert == NO && self.messageDict != nil) {
- [self showAlertWithMemo:[self.messageDict stringValueForKey:@"memo"] descMessage:[self.messageDict stringValueForKey:@"descMessage"] isforce:[self.messageDict boolValueForKey:@"isforce"] openUrl:[self.messageDict stringValueForKey:@"openUrl"]];
- }
- }
- - (void)showAlertWithMemo:(NSString *)memo descMessage:(NSString *)descMessage isforce:(BOOL)isforce openUrl:(NSString *)openUrl {
- if (_isShowFlashAlert) {
- NSMutableDictionary *parm = [NSMutableDictionary dictionary];
- [parm setValue:memo forKey:@"memo"];
- [parm setValue:descMessage forKey:@"descMessage"];
- [parm setValue:@(isforce) forKey:@"isforce"];
- [parm setValue:openUrl forKey:@"openUrl"];
- self.messageDict = [parm mutableCopy];
- return;
- }
- self.messageDict = nil;
- MJWeakSelf;
- [self.alertView configWithMemo:memo desc:descMessage isForce:isforce callback:^(BOOL isSure) {
- weakSelf.isShowMemoAlert = NO;
- if (isSure) {
- if (@available(iOS 10.0, *)) {
- if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:^(BOOL success) {
-
- }];
- } else {
-
- BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
- NSLog(@"Open %d",success);
- }
-
- } else {
- // Fallback on earlier versions
- bool can = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openUrl]];
- if(can){
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
- }
- }
- }
- else {
-
- }
- }];
- [self.alertView showAlert];
- self.isShowMemoAlert = YES;
- }
- - (void)initTableBar {
- if (self.tabBarController) {
- [self.tabBarController removeControllerNotifer];
- }
- self.tabBarController = [[KSTabBarViewController alloc] init];
- self.tabBarController.delegate = self;
- self.window.rootViewController = self.tabBarController;
- int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[ @(ConversationType_PRIVATE),@(ConversationType_APPSERVICE), @(ConversationType_GROUP),@(ConversationType_SYSTEM)
- ]];
- if (unreadMsgCount >= 1) {
- [self.tabBarController noteNewsWithIndex:2 count:unreadMsgCount];
- } else {
- [self.tabBarController clearNewsWithIndex:2];
- }
-
- [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
- [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
- }
- - (void)applicationWillResignActive:(UIApplication *)application {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
-
- RCConnectionStatus status = [[RCIMClient sharedRCIMClient] getConnectionStatus];
- if (status != ConnectionStatus_SignOut) {
- int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[@(ConversationType_PRIVATE), @(ConversationType_APPSERVICE), @(ConversationType_GROUP),@(ConversationType_SYSTEM)]];
- application.applicationIconBadgeNumber = unreadMsgCount;
- if (unreadMsgCount >= 1) {
- [self.tabBarController noteNewsWithIndex:2 count:unreadMsgCount];
- } else {
- [self.tabBarController clearNewsWithIndex:2];
- }
- }
- }
- - (void)didReceiveMessageNotification:(NSNotification *)notification {
- NSNumber *left = [notification.userInfo objectForKey:@"left"];
- if ([RCIMClient sharedRCIMClient].sdkRunningMode == RCSDKRunningMode_Background && 0 == left.integerValue) {
- int unreadMsgCount = [[RCIMClient sharedRCIMClient] getUnreadCount:@[@(ConversationType_PRIVATE), @(ConversationType_APPSERVICE), @(ConversationType_GROUP),@(ConversationType_SYSTEM)]];
- dispatch_async(dispatch_get_main_queue(),^{
- [UIApplication sharedApplication].applicationIconBadgeNumber = unreadMsgCount;
- if (unreadMsgCount >= 1) {
- [self.tabBarController noteNewsWithIndex:2 count:unreadMsgCount];
- } else {
- [self.tabBarController clearNewsWithIndex:2];
- }
- });
- }
- }
- #pragma mark ---- 处理外链
- - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
- NSString *detailUrl = [url absoluteString];
- if ([detailUrl containsString:@"linkUrl="]) {
- NSString *linkUrl = [[detailUrl componentsSeparatedByString:@"linkUrl="] lastObject];
- if (![NSString isEmptyString:linkUrl]) {
- linkUrl = [UrlDecode decodeStringWithString:linkUrl];
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = linkUrl;
-
- UIViewController *vc = self.window.rootViewController;
- if ([vc isKindOfClass:[KSTabBarViewController class]]) {
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl pushViewController:webCtrl animated:YES];
- }
- else {
- UserDefaultSetObjectForKey(linkUrl, WEB_URL);
- }
-
- }
- }
- NSLog(@"%@", detailUrl);
- return YES;
- }
- #pragma mark ---- lazying
- - (KSUpdateAlert *)alertView {
- if (!_alertView) {
- _alertView = [KSUpdateAlert shareInstance];
- }
- return _alertView;
- }
- @end
|