cdts/xdts-ios 3/TreeHole/CYHResetCode/AppDelegate_Extension/AppDelegate+THSetup.m
2023-07-27 09:20:00 +08:00

129 lines
4.5 KiB
Objective-C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppDelegate+THSetup.m
// TreeHole
//
// Created by iOS on 2023/2/2.
//
#import "AppDelegate+THSetup.h"
#import <GTSDK/GeTuiSdk.h>
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/ASIdentifierManager.h>
#import "GeTuiServiceTool+QuickAuthorize.h"
@implementation AppDelegate (THSetup)
#pragma mark - 网络状态
///监听网络状态改变
- (void)setupReachabilityStatusNotification {
[PYHTTPManager setReachabilityStatusChangeBlock:nil];
}
#pragma mark - 个推推送
///初始化个推_推送SDK
- (void)setupGT_PushWithlaunchingOptions:(NSDictionary *)launchOptions {
// 通过个推平台分配的appId、 appKey 、appSecret 启动SDK该方法需要在主线程中调用
[GeTuiSdk startSdkWithAppId:GETUI_APPID appKey:GETUI_APPKEY appSecret:GETUI_APPSECRET delegate:self launchingOptions:launchOptions];
}
#pragma mark - 个推认证
///初始化个推一键认证SDK并预登录
- (void)setupGT_QuickAuthorizeAndPreGetToken {
if (PYAppService.sharedService.gyUid.length) {
[self setGT_QuickAuthorizePreGetToken];
return;
}
[GeTuiServiceTool GT_QuickAuthorizeLoginSetupService:^(BOOL isSuccess, NSError * _Nullable error, NSString * _Nullable gyUid) {
if (!error) { // 与拉取信息
[PYAppService sharedService].gyUid = gyUid;
///预登录
[self setGT_QuickAuthorizePreGetToken];
}
}];
}
///个推-一键认证-预取号
- (void)setGT_QuickAuthorizePreGetToken {
if ([GeTuiServiceTool isPreGettedTokenValidate]) {
return;
}
[GeTuiServiceTool GT_QuickAuthorizePreLoginGetToken:^(BOOL isSuccess, NSDictionary * _Nonnull tokenDic) {
if ([tokenDic[@"code"] intValue] == 30000) {
///NSLog(@"获取token返回结果%@", tokenDic);
[PYAppService sharedService].gyPreTokenDic = tokenDic;
}
}];
}
#pragma mark - IDFA
- (void)setupIDFA {
if (PYAppService.sharedService.idfa.length > 0) {
return;
}
NSString *invalidIdfa = @"00000000-0000-0000-0000-000000000000";
// PYAppService.sharedService.idfa = invalidIdfa;
if (@available(iOS 14, *)) {
// iOS14及以上版本需要先请求权限
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
// 获取到权限后依然使用老方法获取idfa
if (status == ATTrackingManagerAuthorizationStatusAuthorized || status == ATTrackingManagerAuthorizationStatusNotDetermined) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
NSLog(@"%@",idfa);
//上传idfa到服务器
if (![idfa isEqualToString:invalidIdfa]) {
PYAppService.sharedService.idfa = idfa;
[UserService setIdfa:idfa];
// [PYHTTPManager postWithPath:@"uploadidfa" params:@{@"idfa": idfa} callback:^(id _Nullable rsp, NSError * _Nullable error) {
// //
// }];
}
// [self detectionAd];
} else {
NSLog(@"请在设置-隐私-Tracking中允许App请求跟踪");
}
}];
} else {
// iOS14以下版本依然使用老方法
// 判断在设置-隐私里用户是否打开了广告跟踪
if ([[ASIdentifierManager sharedManager] isAdvertisingTrackingEnabled]) {
NSString *idfa = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
//上传idfa到服务器
if (![idfa isEqualToString:invalidIdfa]) {
PYAppService.sharedService.idfa = idfa;
[UserService setIdfa:idfa];
// [PYHTTPManager postWithPath:@"uploadidfa" params:@{@"idfa": idfa} callback:^(id _Nullable rsp, NSError * _Nullable error) {
// //
// }];
}
// [self detectionAd];
} else {
NSLog(@"请在设置-隐私-广告中打开广告跟踪功能");
}
}
}
- (void)detectionAd{
/*
if (_isDetectAd > 0) {
return;
}
if ([UserService registerListenerSucceed] == 0) {
_isDetectAd = 1;
///开屏页面配置
[PYHTTPManager postWithPath:@"lanuchconfigs" params:@{@"idfa": [UserService idfa]} callback:^(id _Nullable rsp, NSError * _Nullable error) {
if (!error) {
}
}];
}
*/
}
@end