Files
yuyin_ios/SweetParty/主类/Others/Other/AppDelegate.m
2025-08-08 11:05:33 +08:00

173 lines
6.3 KiB
Objective-C
Executable File

//
// AppDelegate.m
// qingqiyuyin
//
// Created by bj_szd on 2022/1/18.
//
#import "AppDelegate.h"
#import "SPLaunchVC.h"
#import "SATabBarVC.h"
#import <Bugly/Bugly.h>
#import "MLNetWorkHelper.h"
#import "BJFloatRoomManager.h"
#import "MainNavigationController.h"
#import <BMKLocationkit/BMKLocationComponent.h>
#import <WXApi.h>
#import <AlipaySDK/AlipaySDK.h>
#import <ShareSDK/ShareSDK.h>
#import <CL_ShanYanSDK/CL_ShanYanSDK.h>
#import "TXMicIMService.h"
#import "BJAgoraRtmManager.h"
#import "AvoidCrash.h"
#if DEBUG
#import <LLDebugTool.h>
#endif
@interface AppDelegate () <WXApiDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initThird];
[self initOthers];
#if DEBUG
[[LLDebugTool sharedTool] startWorking];
#endif
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
MainNavigationController *nav = [[MainNavigationController alloc] initWithRootViewController:[SPLaunchVC new]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
- (void)initThird {
[Bugly startWithAppId:@"4aae33d1b1"];
//屏蔽masonry警告打印
[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];
// [[BMKLocationAuth sharedInstance] setAgreePrivacy:YES];
// [[BMKLocationAuth sharedInstance] checkPermisionWithKey:Baidu_AK authDelegate:self];
// [CLShanYanSDKManager initWithAppId:SHANYAN_APP_ID complete:nil];
//务必在调用自检函数前注册
[WXApi registerApp:WX_APP_ID universalLink:MOB_Universal_Link];
// [ShareSDK registPlatforms:^(SSDKRegister *platformsRegister) {
// [platformsRegister setupWeChatWithAppId:WX_APP_ID appSecret:WX_APP_KEY universalLink:MOB_Universal_Link];
// [platformsRegister setupQQWithAppId:QQ_APP_ID appkey:QQ_APP_KEY enableUniversalLink:YES universalLink:MOB_Universal_Link];
// }];
//全局捕捉数组、字典越界等
[AvoidCrash becomeEffective];
}
- (void)initOthers {
if (@available(iOS 11.0, *)){
[[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
}
if (@available(iOS 15.0, *)) {
[UITableView appearance].sectionHeaderTopPadding = 0;
[UITableView appearance].prefetchingEnabled = NO;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginRefresh) name:kLoginSucessNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kickedOffLineAction) name:TXIMDinghaoNoti object:nil];
}
#pragma mark - 用户在别处登录,被挤掉提示
- (void)kickedOffLineAction {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//弹出提示框被挤下线
[[NSNotificationCenter defaultCenter] postNotificationName:@"stopPlayYinyue" object:nil];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"下线通知" message:@"您的账号在别的设备登录,您已被迫下线" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
dispatch_async(dispatch_get_main_queue(), ^{
[APPDELEGATE setupLoginViewController];
});
[BJFloatRoomManager.sharedBJFloatRoomManager closeFloatWindow];
// [[RCIMClient sharedRCIMClient] logout];
[BJUserManager clearUserInfo];
[MLRoomInformationManager clearUserInfo];
}]];
// 由于它是一个控制器 直接modal出来就好了
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
});
}
#pragma mark - 登录后链接融云
- (void)loginRefresh {
//连接腾讯IM
[[TXMicIMService sharedService] initTXIMWithAppID:[GVUSER.tencentyun_im_appid intValue] userID:BJUserManager.userInfo.uid userSig:BJUserManager.userInfo.user_sig];
// //链接融云
// [[RCMicAppService sharedService] configUserEnvironment:BJUserManager.userInfo];
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
SATabBarVC *mainVC = SATabBarVC.sharedSATabBarVC;
weakSelf.window.rootViewController = mainVC;
});
}
//登录页面
-(void)setupLoginViewController{
[BJUserManager clearUserInfo];
[[BJAgoraRtmManager shared] logoutAndLeaveChannel];
// [[RCIMClient sharedRCIMClient] logout];
[UIViewController.currentViewController.navigationController popToRootViewControllerAnimated:YES];
SATabBarVC.sharedSATabBarVC.selectedIndex = 0;
if ([UIViewController.currentViewController isKindOfClass:SPLoginVC.class]) {
return;
}
// if ([UIViewController.currentViewController isKindOfClass:MH_ForgetVC.class]) {
// return;
// }
SPLoginVC *vc = [[SPLoginVC alloc] init];
MainNavigationController *navVC = [[MainNavigationController alloc] initWithRootViewController:vc];
self.window.rootViewController = navVC;
}
#pragma mark ----------------支付宝支付
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
//跳转支付宝钱包进行支付,处理支付结果
if ([url.host isEqualToString:@"safepay"]) {
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:nil];
}else{
[WXApi handleOpenURL:url delegate:self];
}
return YES;
}
-(void)onResp:(BaseResp*)resp{
if ([resp isKindOfClass:[PayResp class]]){
PayResp *response=(PayResp*)resp;
switch(response.errCode){
case WXSuccess:
[[NSNotificationCenter defaultCenter] postNotificationName:@"wechatPayResult" object:@"1"];
break;
case WXErrCodeUserCancel:
[[NSNotificationCenter defaultCenter] postNotificationName:@"wechatPayResult" object:@"2"];
break;
default:
[[NSNotificationCenter defaultCenter] postNotificationName:@"wechatPayResult" object:@"3"];
break;
}
}
}
@end