Files
featherVoice/QXLive/Other/AppDelegate.m

241 lines
9.1 KiB
Mathematica
Raw Normal View History

2025-08-08 10:49:36 +08:00
//
// AppDelegate.m
// QXLive
//
// Created by on 2025/4/24.
//
#import "AppDelegate.h"
#import "AppDelegate+Login.h"
#import "QXFillUserInfoViewController.h"
#import "AvoidCrash.h"
#import <WXApi.h>
#import <Bugly/Bugly.h>
#import <AlipaySDK/AlipaySDK.h>
#import <TIMPush/TIMPushManager.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
#if DEBUG
#import <LLDebugTool.h>
#endif
@interface AppDelegate ()<WXApiDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[QXConfig defaultConfig];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
if ([QXGlobal shareGlobal].isLogin && [[QXGlobal shareGlobal].loginModel.sex isEqualToString:@"0"]) {
QXFillUserInfoViewController *vc = [[QXFillUserInfoViewController alloc] init];
self.window.rootViewController = vc;
}else{
self.tabbarVC = [[QXTabbarController alloc] init];
QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:self.tabbarVC];
na.navigationBarHidden = YES;
self.window.rootViewController = na;
}
[Bugly startWithAppId:@"38d154fc5f"];
SDImageWebPCoder *webPCoder = [SDImageWebPCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:webPCoder];
[self configThirdPartLogin];
#if DEBUG
[[LLDebugTool sharedTool] startWorking];
#endif
[self crash];
[self.window makeKeyAndVisible];
return YES;
}
-(void)crash{
NSArray *noneSelClassStrings = @[
@"NSNull",
@"NSNumber",
@"NSString",
@"NSDictionary",
@"NSArray"
];
[AvoidCrash setupNoneSelClassStringsArr:noneSelClassStrings];
[AvoidCrash becomeEffective];
}
-(void)changeRootViewControllerIsTabbar{
self.tabbarVC = [[QXTabbarController alloc] init];
QXBaseNavigationController *na = [[QXBaseNavigationController alloc] initWithRootViewController:self.tabbarVC];
na.navigationBarHidden = YES;
self.window.rootViewController = na;
}
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
BOOL result =[WXApi handleOpenUniversalLink:userActivity delegate:self];
return result;
}
// NOTE: 9.0使API
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options{
if ([url.host isEqualToString:@"safepay"]) {
//
[[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
NSLog(@"result = %@",resultDic);
NSString *result = [NSString stringWithFormat:@"%@",resultDic[@"memo"]];
NSString *resultStatus = [NSString stringWithFormat:@"%@",resultDic[@"resultStatus"]];
if (resultStatus.intValue == 9000) {
showToast(@"支付成功");
[[NSNotificationCenter defaultCenter] postNotificationName:noticeAlipayResult object:nil];
}else{
showToast(result);
}
}];
// //
// [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
// NSLog(@"result = %@",resultDic);
// // auth code
// NSString *result = resultDic[@"result"];
// NSString *authCode = nil;
// if (result.length>0) {
// NSArray *resultArr = [result componentsSeparatedByString:@"&"];
// for (NSString *subResult in resultArr) {
// if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
// authCode = [subResult substringFromIndex:10];
// break;
// }
// }
// }
// NSLog(@"授权结果 authCode = %@", authCode?:@"");
// [[NSNotificationCenter defaultCenter]postNotificationName:@"RELOADBLANCE" object:nil];
// }];
[[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
QXLOG(@"auth = %@",resultDic);
NSString *result = resultDic[@"result"];
NSString *authCode = nil;
if (result.length>0) {
NSArray *resultArr = [result componentsSeparatedByString:@"&"];
for (NSString *subResult in resultArr) {
if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
authCode = [subResult substringFromIndex:10];
break;
}
}
}
NSLog(@"授权结果 authCode = %@", authCode?:@"");
}];
}else if ([url.host isEqualToString:@"pay"]){
return [WXApi handleOpenURL:url delegate:self];
}else if ([url.host isEqualToString:@"oauth"]){
return [WXApi handleOpenURL:url delegate:self];
}else{
return [WXApi handleOpenURL:url delegate:self];
}
return YES;
}
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
//{
// if ([url.host isEqualToString:@"safepay"]) {
// //
// [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
// NSLog(@"result = %@",resultDic);
// }];
//
// //
// [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
// NSLog(@"result = %@",resultDic);
// // auth code
// NSString *result = resultDic[@"result"];
// NSString *authCode = nil;
// if (result.length>0) {
// NSArray *resultArr = [result componentsSeparatedByString:@"&"];
// for (NSString *subResult in resultArr) {
// if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
// authCode = [subResult substringFromIndex:10];
// break;
// }
// }
// }
// NSLog(@"授权结果 authCode = %@", authCode?:@"");
// }];
// }
// return YES;
//}
-(void)onResp:(BaseResp *)resp
{
if ([resp isKindOfClass:[PayResp class]])
{
PayResp *response = (PayResp *)resp;
switch (response.errCode)
{
case WXSuccess:
//API
NSLog(@"支付成功");
showToast(QXText(@"支付成功"));
// [[NSNotificationCenter defaultCenter] postNotificationName:@"wxapiPaySuccess" object:nil userInfo:nil];
break;
case WXErrCodeUserCancel:
//API
//
showToast(QXText(@"取消支付"));
break;
default:
NSLog(@"支付失败, retcode=%d",resp.errCode);
showToast(QXText(@"支付失败"));
break;
}
}else if([resp isKindOfClass:[SendAuthResp class]]){
SendAuthResp *response = (SendAuthResp *)resp;
[[NSNotificationCenter defaultCenter] postNotificationName:noticeWeChatLogin object:response];
}
}
///
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
// ZFInterfaceOrientationMask orientationMask = [ZFLandscapeRotationManager supportedInterfaceOrientationsForWindow:window];
// if (orientationMask != ZFInterfaceOrientationMaskUnknow) {
// return (UIInterfaceOrientationMask)orientationMask;
// }
/// VC
if (_allowRotate == 1) {
return UIInterfaceOrientationMaskLandscapeRight;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
//
- (BOOL)shouldAutorotate
{
if (_allowRotate == 1) {
return YES;
}
return NO;
}
#pragma mark - TIMPush
#pragma mark - TIMPush
- (int)businessID {
//ID 1234567
return AppPushId;
}
//- (NSString *)applicationGroupID {
// //AppGroup ID
// return kTIMPushAppGroupKey;
//}
- (BOOL)onRemoteNotificationReceived:(NSString *)notice {
// custom navigate
return NO;
}
#pragma mark - TIMPushListener
- (void)onNotificationClicked:(NSString *)ext {
// ext
}
@end