123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- #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>
- #import <UMShare/UMShare.h>
- #import <UShareUI/UShareUI.h>
- #import "JPUSHService.h"
- #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"
- #import "GuideViewController.h"
- #import "HomeworkDetailViewController.h"
- #import "MyCourseViewController.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,JPUSHRegisterDelegate>
- @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 {
-
- [self networkEnableCheck];
- [self registerSDK];
- [Bugly startWithAppId:@"adfcb3bc3d"];
-
- if (@available(iOS 13.0, *)) {
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
- } else {
-
- [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
- }
-
- [[UITabBar appearance] setTranslucent:NO];
-
- [[UITextField appearance] setTintColor:THEMECOLOR];
- [[UITextView appearance] setTintColor:THEMECOLOR];
-
-
- [self configJPUSHWithLaunchOptions:launchOptions];
-
- [self configIM];
- BOOL hasLaunchGuide = UserDefaultBoolForKey(FIRST_LOGIN_KEY);
- if (hasLaunchGuide == NO) {
- GuideViewController *guideVC = [[GuideViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:guideVC];
- self.window.rootViewController = navCtrl;
- }
- else {
- 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 {
-
- }
-
- [IQKeyboardManager sharedManager].enable = YES;
- [IQKeyboardManager sharedManager].toolbarManageBehaviour = IQAutoToolbarByPosition;
- [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
- [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 10.0f;
- [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
-
-
- [self registerRemoteNotification:application];
-
-
- [self versionCheck];
-
- if(@available(iOS 11.0, *)){
-
- [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[UIDocumentBrowserViewController class]]].tintColor = THEMECOLOR;
- }
- return YES;
- }
- - (void)registerSDK {
- [WXApi registerApp:@"wx97408cd22c879ff7" universalLink:@"https://dev.colexiu.com/studentApp/"];
- }
- - (void)appTrackActionAuth {
- if (self.hasCheckTrackAuth == NO) {
- if (@available(iOS 14, *)) {
- [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
- [self configUM];
- }];
- } else {
-
- [self configUM];
- }
- self.hasCheckTrackAuth = YES;
- }
- }
- - (void)configUM {
- [UMConfigure initWithAppkey:@"62a2a806eae04539a8e253ed" channel:@"App Store"];
-
-
-
- [UMSocialGlobal shareInstance].universalLinkDic = @{@(UMSocialPlatformType_WechatSession):@"https://dev.colexiu.com/studentApp/",@(UMSocialPlatformType_Sina):@"https://dev.colexiu.com/studentApp/"};
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:@"wx97408cd22c879ff7" appSecret:@"d3f119b577ccacb262da153f4210174f" redirectURL:nil];
-
- [[UMSocialManager defaultManager] removePlatformProviderWithPlatformTypes:@[@(UMSocialPlatformType_WechatFavorite)]];
-
- [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:@"3712190405" appSecret:@"e77924e0125dbd751bab61063d8338fb" redirectURL:nil];
-
- }
- - (void)versionCheck {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [KSUpdateManager ks_updateWithAPPID:@"1626971695" 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]) {
-
- 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 {
-
- 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];
-
- [JPUSHService setupWithOption:launchOptions appKey:@"911d07f359c18a078f29792f"
- channel:nil
- apsForProduction:JSPUSH_ENVIRONMENT
- advertisingIdentifier:nil];
- }
- - (void)configIM {
- [RCNaviDataManager sharedInstance].naviData.uploadVideoDurationLimit = 480.0f;
-
- [[RCIM sharedRCIM] initWithAppKey:RCIM_KEY];
-
-
- [[RCIM sharedRCIM] setConnectionStatusDelegate:KSRMLINK];
-
- [[RCIM sharedRCIM] setReceiveMessageDelegate:self];
-
- [RCIM sharedRCIM].userInfoDataSource = KSRMDataSource;
- [[RCIM sharedRCIM] setGroupInfoDataSource:KSRMDataSource];
-
- [[RCIM sharedRCIM] setGroupUserInfoDataSource:KSRMDataSource];
-
- [RCIM sharedRCIM].groupMemberDataSource = KSRMDataSource;
-
-
- 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;
-
- [RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
-
- RCKitConfigCenter.message.disableMessageAlertSound = YES;
-
-
-
-
-
- RCKitConfigCenter.ui.globalNavigationBarTintColor = HexRGB(0x000000);
-
-
- [[RCIM sharedRCIM] registerMessageType:NSClassFromString(@"KSChatLiveMessage")];
- [[RCIM sharedRCIM] registerMessageType:NSClassFromString(@"KSChatMusicMessage")];
-
-
-
-
- }
- #pragma mark - private method
- - (void)registerRemoteNotification:(UIApplication *)application {
-
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
-
- UIUserNotificationSettings *settings = [UIUserNotificationSettings
- settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)
- categories:nil];
- [application registerUserNotificationSettings:settings];
- } else {
-
- UIRemoteNotificationType myTypes =
- UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
- [application registerForRemoteNotificationTypes:myTypes];
- }
- #pragma clang diagnostic pop
- }
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- #pragma clang diagnostic ignored "-Wdeprecated-implementations"
- - (void)application:(UIApplication *)application
- didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
- [application registerForRemoteNotifications];
- }
- #pragma clang diagnostic pop
- - (void)application:(UIApplication *)application
- didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
-
-
- [JPUSHService registerDeviceToken:deviceToken];
-
-
- [[RCIMClient sharedRCIMClient] setDeviceTokenData:deviceToken];
- }
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
-
- NSDictionary *pushServiceData = [[RCIMClient sharedRCIMClient] getPushExtraFromRemoteNotification:userInfo];
- if (pushServiceData) {
- NSLog(@"该远程推送包含来自融云的推送服务");
-
- [[RCIMClient sharedRCIMClient] recordRemoteNotificationEvent:userInfo];
-
- for (id key in [pushServiceData allKeys]) {
- NSLog(@"key = %@, value = %@", key, pushServiceData[key]);
- }
- } else {
- NSLog(@"该远程推送不包含来自融云的推送服务");
-
- [JPUSHService handleRemoteNotification:userInfo];
- }
- }
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-implementations"
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
-
- [[RCIMClient sharedRCIMClient] recordRemoteNotificationEvent:userInfo];
-
- 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];
- }
- }
- #pragma clang diagnostic pop
- - (void)applicationDidEnterBackground:(UIApplication *)application {
-
-
-
- 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 {
-
- 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 {
-
- }
- - (void)applicationWillTerminate:(UIApplication *)application {
-
- }
- - (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.conversationType == ConversationType_GROUP && ![message.targetId containsString:@"COURSE"] && ![message.targetId containsString:@"FAN"]) {
- [[RCIMClient sharedRCIMClient] clearMessagesUnreadStatus:ConversationType_GROUP targetId:message.targetId];
- [[KSIMService sharedService] ksOnReceived:message left:left object:@""];
- }
- else {
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if ([message.content isMemberOfClass:[RCGroupNotificationMessage class]]) {
- RCGroupNotificationMessage *msg = (RCGroupNotificationMessage *)message.content;
- if ([msg.operation isEqualToString:GroupNotificationMessage_GroupOperationKicked]) {
-
- }
- }
- 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];
- }
- }
- });
- }
-
- }
- #pragma mark- JPUSHRegisterDelegate
- - (void)jpushNotificationAuthorization:(JPAuthorizationStatus)status withInfo:(NSDictionary *)info {
- NSLog(@"receive notification authorization status:%lu, info:%@", status, info);
- }
- #ifdef __IPHONE_12_0
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {
- NSString *title = nil;
- if (notification) {
- title = @"从通知界面直接进入应用";
- }else{
- title = @"从系统设置界面进入应用";
- }
- NSLog(@"%@", title);
- }
- #endif
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler API_AVAILABLE(ios(10.0)){
-
- NSDictionary * userInfo = notification.request.content.userInfo;
- if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
- }
- if (@available(iOS 10.0, *)) {
- completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound);
- } else {
-
- }
- }
- - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
-
- NSDictionary * userInfo = response.notification.request.content.userInfo;
- if (@available(iOS 10.0, *)) {
- if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
- [JPUSHService handleRemoteNotification:userInfo];
- }
- } else {
-
- }
- completionHandler();
- NSMutableDictionary *parm = [NSMutableDictionary dictionaryWithDictionary:userInfo];
-
- [self getVCUserInfoDict:parm];
- }
- #pragma mark 根据不同消息跳转不同界面
- - (void)getVCUserInfoDict:(NSMutableDictionary *)infoDict {
- if (![NSString isEmptyString:[infoDict stringValueForKey:@"memo"]]) {
- NSData *jsonData = [[infoDict stringValueForKey:@"memo"] mj_JSONData];
- NSError *error;
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
- if (!error) {
- NSString *action = [dict stringValueForKey:@"action"];
- if ([action isEqualToString:@"app"]) {
- NSString *pageType = [dict stringValueForKey:@"pageTag"];
- if ([pageType isEqualToString:@"buyPractice"] || [pageType isEqualToString:@"courseRemind"]) {
- [self.tabBarController tabBarSelectedWithIndex:1];
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl popToRootViewControllerAnimated:YES];
- }
- else if ([pageType isEqualToString:@"homework"]) {
- NSString *parmString = [dict stringValueForKey:@"params"];
- NSData *parmData = [parmString mj_JSONData];
- NSDictionary *parm = [NSJSONSerialization JSONObjectWithData:parmData options:NSJSONReadingMutableContainers error:&error];
- if (!error) {
- HomeworkDetailViewController *detailVC = [[HomeworkDetailViewController alloc] init];
- detailVC.courseId = [parm stringValueForKey:@"courseId"];
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl pushViewController:detailVC animated:YES];
- }
- }
- }
- else {
- NSString *webUrl = [dict stringValueForKey:@"url"];
- if (![NSString isEmptyString:webUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = webUrl;
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl pushViewController:webCtrl animated:YES];
- }
- }
- }
- }
- }
- - (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;
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
- 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 {
-
- bool can = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openUrl]];
- if(can){
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
- }
- }
- }
- else {
-
- }
- }];
- #pragma clang diagnostic pop
- [self.alertView showAlert];
- self.isShowMemoAlert = YES;
- }
- - (void)requestRongCloudToken {
- [KSNetworkingManager refreshImTokenRequest:KS_POST success:^(NSDictionary * _Nonnull dic) {
- if ([dic integerValueForKey:@"code"] == 200 && [dic boolValueForKey:@"status"]) {
- NSString *newToken = [dic stringValueForKey:@"data"];
- if (![NSString isEmptyString:newToken]) {
- UserDefaultSet(newToken, RongTokenKey);
- [[NSUserDefaults standardUserDefaults] synchronize];
- [USER_MANAGER checkTokenEnableConnectRongCloud];
- }
- }
- else {
- NSLog(@"error");
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (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)initLoginView {
- LoginViewController *logonVC = [[LoginViewController alloc] init];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:logonVC];
- self.window.rootViewController = navCtrl;
- }
- - (void)applicationWillResignActive:(UIApplication *)application {
-
-
-
- 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];
-
- NSData *jsonData = [linkUrl mj_JSONData];
- NSError *error;
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
- if (error) {
- NSLog(@"jsonString解析失败:%@", error);
- return NO;
- }
- else {
- NSString *action = [dict stringValueForKey:@"action"];
- if ([action isEqualToString:@"app"]) {
- NSString *pageType = [dict stringValueForKey:@"pageTag"];
- DISPLAY_INDEX index = DISPLAY_INDEX_FIRST;
- if ([pageType isEqualToString:@"practiceClass"]) {
- index = DISPLAY_INDEX_FIRST;
- }
- else if ([pageType isEqualToString:@"liveClass"]) {
- index = DISPLAY_INDEX_LIVE;
- }
- else if ([pageType isEqualToString:@"videoClass"]) {
- index = DISPLAY_INDEX_VIEO;
- }
- MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
- [ctrl displayWithIndex:index];
- CustomNavViewController *navCtrl = self.tabBarController.selectedViewController;
- [navCtrl pushViewController:ctrl animated:YES];
- }
- else {
- NSString *webUrl = [dict stringValueForKey:@"url"];
- if (![NSString isEmptyString:webUrl]) {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = webUrl;
-
- 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;
- }
- - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
- NSString* webpageStr = userActivity.webpageURL.absoluteString;
- if ([webpageStr containsString:@"wx97408cd22c879ff7"] && [webpageStr containsString:@"pay"]) {
- BOOL isok = [WXApi handleOpenUniversalLink:userActivity delegate:self];
- if (isok) {
- return YES;
- }
- }
- if (![[UMSocialManager defaultManager] handleUniversalLink:userActivity options:nil]) {
-
-
- }
- return YES;
- }
- #pragma mark ---- lazying
- - (KSUpdateAlert *)alertView {
- if (!_alertView) {
- _alertView = [KSUpdateAlert shareInstance];
- }
- return _alertView;
- }
- @end
|