cdts/xdts-ios 3/TreeHole/Code/AppDelegate.m

254 lines
11 KiB
Mathematica
Raw Normal View History

2023-07-27 09:20:00 +08:00
//
// AppDelegate.m
// AppScaffold
//
// Created by on 2020/3/14.
// Copyright © 2020 ko1o. All rights reserved.
//
#import "AppDelegate.h"
#import "AppSetup.h"
#import "TUILogin.h"
#import <WXApi.h>
#import <Bugly/Bugly.h>
#import "ApplePayService.h"
#import <V2TIMManager+APNS.h>
#import "TUIMessageDataProvider+TUIPatch.h"
//#import <UMShare/UMShare.h>
//#import <BaiduActionSDK/BaiduAction.h>
#import "AppDelegate+THSetup.h"
#import "AppDelegate+THCustomTabBarController.h"
//#import "CYHProvinceCityAreaHelper.h"
//#import "THLivePlayScrollViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [self setupCustomTabBarControllerAndAppearance];
// return YES;
[self setupReachabilityStatusNotification];
[PYHTTPManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
//
BOOL isWanAndWifi = (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi);
if (isWanAndWifi) {
[self setupGT_QuickAuthorizeAndPreGetToken];
[self setupIDFA];
}
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:LoginSuccessNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:LogoutSuccessNotification object:nil];
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.window.rootViewController = [[THNavigationController alloc] initWithRootViewController:[THLivePlayScrollViewController new]];
// [self.window makeKeyAndVisible];
// return YES;
// app
[PYAppService appConfig];
[TUILogin initWithSdkAppID:TIM_APPID]; // SDKAppID IM
[Bugly startWithAppId:BUGLY_APPID];
// apple pay
[[ApplePayService sharedInstance] autoHandleUpdatedTransactions];
//
[AppSetup initSetupWithWindow:self.window];
//
[PYAppService sharedService];
///_SDK
[self setupGT_PushWithlaunchingOptions:launchOptions];
// [BaiduAction init:@"16447" secretKey:@"76ddbf4c626e5ed4612607dfbbb6eaad"];
//
[NSThread sleepForTimeInterval:1.5];
return YES;
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskPortrait; //
}
- (void)loginSuccess {
[AppSetup setupWindowRootVCWithWindow:self.window isLanuch:NO];
}
- (void)logoutSuccess {
[AppSetup setupWindowRootVCWithWindow:self.window isLanuch:NO];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
// if ([[UMSocialManager defaultManager] handleUniversalLink:userActivity options:nil]) {
// // SDK
// return YES;
// }
//
if ([WXApi handleOpenUniversalLink:userActivity delegate:[PYAppService sharedService]]) {
return YES;
}
if ([PYAppService handleUrl:userActivity.webpageURL.absoluteString]) {
return YES;
}
return NO;
}
// iOS9
- (BOOL)application:(UIApplication*)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options
{
//
if ([WXApi handleOpenURL:url delegate:[PYAppService sharedService]]) {
return YES;
} else if ([url.host isEqualToString:@"safepay"]) {
//
// [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
// NSLog(@"result = %@",resultDic);
// [PYAppService checkPayResult];
// }];
}
// 6.3API(:facebookSDK,VK)[6.2api],
// if ([[UMSocialManager defaultManager] handleOpenURL:url options:options]) {
// // SDK
// return YES;
// }
if ([PYAppService handleUrl:url.absoluteString]) {
return YES;
}
return NO;
}
#pragma mark - Notification
// AppDelegate deviceToken
-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Apple deviceToken
self.deviceToken = deviceToken;
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"\n>>>[DeviceToken Success]:%@\n\n", token);
V2TIMAPNSConfig *confg = [[V2TIMAPNSConfig alloc] init];
/* (p12 ) p12 ID ID busiId */
// ID
confg.businessID = TIM_PUSHID;
// confg.token = self.deviceToken;
NSLog(@"push token %@", [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]);
confg.token = deviceToken;
[[V2TIMManager sharedInstance] setAPNS:confg succ:^{
NSLog(@"register push success");
} fail:^(int code, NSString *msg) {
NSLog(@"register push fail %s %d, %@", __func__, code, msg);
}];
}
-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error
{
NSLog(@"register push fail %@", error);
}
// APP
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
// desc
if ([userInfo[@"ext"] isEqualToString:NewC2CMessage]) {
//TODO hely @peiyi rootviewcontroolerTab
[PYAppService setTabbarSelectedItem:0];
}
}
#pragma mark - Getui SDK Delegate
/// [ GTSDK ] SDK
- (void)GeTuiSDkDidNotifySdkState:(SdkStatus)aStatus {
NSLog(@"GeTuiSDkDidNotifySdkState %lu", (unsigned long)aStatus);
}
/** SDKcid */
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
//SDKclientId
NSLog(@"\n>>>[GeTuiSdk RegisterClient]:%@\n\n", clientId);
}
#pragma mark - Getui Push
//// push
/// iOS10
/// @param center center
/// @param notification notification
/// @param completionHandler completionHandler
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification completionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), notification.request.content.userInfo];
NSLog(@"%@", msg);
// [ ] APPBadgeSoundAlert
//completionHandler(UNNotificationPresentationOptionNone);
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
///
/// @param userInfo apns
/// @param center UNUserNotificationCenteriOS10
/// @param response UNNotificationResponseiOS10
/// @param completionHandler iOS10
- (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo notificationCenter:(UNUserNotificationCenter *)center response:(UNNotificationResponse *)response fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), userInfo];
NSLog(@"%@", msg);
if(completionHandler) {
// [ ] APP
completionHandler(UIBackgroundFetchResultNoData);
}
}
///
/// @param userInfo
/// @param fromGetui YES: NOapns
/// @param offLine 线YES.线
/// @param appId appId
/// @param taskId id
/// @param msgId messageid
/// @param completionHandler apns
- (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo fromGetui:(BOOL)fromGetui offLine:(BOOL)offLine appId:(NSString *)appId taskId:(NSString *)taskId msgId:(NSString *)msgId fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
// [ GTSDK ]()使,
// [GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APN] %@ \nReceive Slience: fromGetui:%@ appId:%@ offLine:%@ taskId:%@ msgId:%@ userInfo:%@ ", NSStringFromSelector(_cmd), fromGetui ? @"个推消息" : @"APNs消息", appId, offLine ? @"离线" : @"在线", taskId, msgId, userInfo];
NSLog(@"%@", msg);
if(completionHandler) {
// [ ] APP
completionHandler(UIBackgroundFetchResultNoData);
}
}
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {
// [ ] APP
}
- (void)GeTuiSdkDidOccurError:(NSError *)error {
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [GeTuiSdk GeTuiSdkDidOccurError]:%@\n\n",error.localizedDescription];
// SDK
NSLog(@"%@", msg);
}
@end