244 lines
9.6 KiB
Objective-C
244 lines
9.6 KiB
Objective-C
//
|
||
// AppDelegate+LuxAppDelegate.m
|
||
// TallPaper
|
||
//
|
||
// Created by aaa on 2024/7/30.
|
||
//
|
||
|
||
#import "LuxADConfigure.h"
|
||
#import <objc/runtime.h>
|
||
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
||
#import <AdSupport/ASIdentifierManager.h>
|
||
|
||
#import <Firebase/Firebase.h>
|
||
#import <FirebaseCore/FirebaseCore.h>
|
||
#import <FirebaseRemoteConfig/FirebaseRemoteConfig.h>
|
||
#import <FirebaseAnalytics/FirebaseAnalytics.h>
|
||
|
||
|
||
//替换为自己需要用到的VC类头文件
|
||
#import "OneVC.h"
|
||
#import "twoVC.h"
|
||
#import "threeVC.h"
|
||
@interface LuxADConfigure()
|
||
@property (nonatomic,strong) NSTimer *attTimer;
|
||
|
||
@end
|
||
|
||
#define ZH_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f]
|
||
@implementation LuxADConfigure
|
||
|
||
+ (instancetype)shareInstance {
|
||
static LuxADConfigure *instance = nil;
|
||
static dispatch_once_t onceToken;
|
||
dispatch_once(&onceToken, ^{
|
||
instance = [LuxADConfigure new];
|
||
});
|
||
return instance;
|
||
}
|
||
|
||
//检查idfa的att弹框
|
||
- (void)checkATT{
|
||
self.attTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(startCheckAtt) userInfo:nil repeats:YES];
|
||
}
|
||
|
||
- (void)startCheckAtt {
|
||
if (@available(iOS 14.0,*)) {
|
||
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
||
// 获取到权限后,依然使用老方法获取idfa
|
||
if(status == ATTrackingManagerAuthorizationStatusNotDetermined) {
|
||
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
||
if (status != ATTrackingManagerAuthorizationStatusNotDetermined) {
|
||
NSLog(@"用户已做出选择");
|
||
[self invalidATTTimer];
|
||
}
|
||
else {
|
||
NSLog(@"用户未做出选择,可能是弹框未弹出...");
|
||
}
|
||
}];
|
||
NSLog(@"att status ATTrackingManagerAuthorizationStatusNotDetermined :%lu",status);
|
||
}
|
||
else{
|
||
NSLog(@"att status :%lu",status);
|
||
[self invalidATTTimer];
|
||
}
|
||
}];
|
||
}
|
||
}
|
||
|
||
|
||
-(void)invalidATTTimer{
|
||
if( self.attTimer ){
|
||
[self.attTimer invalidate];
|
||
}
|
||
self.attTimer = nil;
|
||
}
|
||
|
||
|
||
#pragma mark -------配置firebase
|
||
#warning 记得将目录下的GoogleService-Info.plist文件替换为当前app的firebase配置
|
||
- (void)configureADByFirebaseWith:(UIWindow *)window {
|
||
[FIRApp configure];
|
||
UIViewController *vc = [UIViewController new];
|
||
vc.view.backgroundColor = [UIColor colorWithRed:30.0/255.0 green:144.0/255.0 blue:255.0/255.0 alpha:1];
|
||
UIImageView *bgImgView = [UIImageView new];
|
||
[vc.view addSubview:bgImgView];
|
||
bgImgView.image = [UIImage imageNamed:@"logo"];
|
||
bgImgView.frame = CGRectMake((window.frame.size.width - 80) * 0.5, (window.frame.size.height - 80) * 0.5,80,80);
|
||
bgImgView.layer.masksToBounds = YES;
|
||
bgImgView.layer.cornerRadius = 40;
|
||
bgImgView.contentMode = UIViewContentModeScaleAspectFit;
|
||
|
||
window.rootViewController = vc;
|
||
[window makeKeyAndVisible];
|
||
if (![LuxADManager shareInstance].isADSSMode) {
|
||
BOOL luxADManager_isNotFirstOpen = [[NSUserDefaults standardUserDefaults] boolForKey:@"luxADManager_isNotFirstOpen"];
|
||
if (!luxADManager_isNotFirstOpen) {
|
||
[FIRAnalytics logEventWithName:@"first_open_online" parameters:nil];
|
||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"luxADManager_isNotFirstOpen"];
|
||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
}
|
||
|
||
}
|
||
|
||
|
||
[self cycleConfigureADByFirebaseWith:window];
|
||
}
|
||
|
||
- (void)cycleConfigureADByFirebaseWith:(UIWindow *)window {
|
||
if ([[LuxADManager shareInstance] isADSSMode] ) {
|
||
[self configureADWith:window];
|
||
}
|
||
else {//读取firebase数据
|
||
//判断之前是否已经isOpen,是,就直接进行configure视图,不必再等firebase数据
|
||
BOOL old_isadopen = [[NSUserDefaults standardUserDefaults] boolForKey:@"lux_cycleConfigure_isadopen_key"];
|
||
if (old_isadopen) {
|
||
[self configureADWith:window];
|
||
}
|
||
|
||
|
||
__weak typeof(self)weakSelf = self;
|
||
FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
|
||
FIRRemoteConfigSettings *rcs = [FIRRemoteConfigSettings new];
|
||
rcs.minimumFetchInterval = 0;
|
||
rcs.fetchTimeout = 6;
|
||
rc.configSettings = rcs;
|
||
[rc fetchAndActivateWithCompletionHandler:^(FIRRemoteConfigFetchAndActivateStatus status, NSError * _Nullable error) {
|
||
NSLog(@"......");
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) {
|
||
|
||
NSString *localVer = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"];
|
||
NSDictionary *value = [[rc configValueForKey:@"isopen"] JSONValue];
|
||
BOOL isadopen = [value[@"isadopen"] boolValue];
|
||
NSString *version = value[@"version"];
|
||
if (!isadopen || ( version && [version isEqualToString:localVer])) {//不展示ad
|
||
if (!old_isadopen) {
|
||
[weakSelf configureRootVCWith:window];
|
||
}
|
||
|
||
}
|
||
else {
|
||
if (!old_isadopen) {
|
||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"lux_cycleConfigure_isadopen_key"];
|
||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
[weakSelf configureADWith:window];
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
//获取b面的localurl配置回写
|
||
NSString *localUrl = value[@"adbrush_base_url"];
|
||
if (localUrl) {
|
||
NSDictionary *bfaceDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"bfaceDictKey"];
|
||
NSMutableDictionary *mdic = [NSMutableDictionary new];
|
||
if (bfaceDict) {
|
||
mdic = [NSMutableDictionary dictionaryWithDictionary:bfaceDict];
|
||
}
|
||
[mdic setObject:localUrl forKey:@"adbrush_base_url"];
|
||
[[NSUserDefaults standardUserDefaults] setObject:mdic forKey:@"bfaceDictKey"];
|
||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||
}
|
||
|
||
}
|
||
else {
|
||
if (!old_isadopen) {
|
||
[weakSelf configureRootVCWith:window];
|
||
}
|
||
|
||
}
|
||
});
|
||
|
||
|
||
}];
|
||
}
|
||
}
|
||
|
||
|
||
#pragma mark -----配置AD
|
||
#warning 请把以下的id与key替换为对应项目的max 账户信息; 同时,请将每个actionBlock中的代码改为点击每个广告需要跳转的页面
|
||
- (void)configureADWith:(UIWindow *)window {
|
||
|
||
[[LuxADManager shareInstance] addADWithInterstitialId:@"bee9f7039e56cc7a" actionBlock:^(UIViewController * _Nonnull vc) {
|
||
|
||
}];//第一个一定为开屏插页
|
||
|
||
[[LuxADManager shareInstance] addADWithInterstitialId:@"8fccdfa964b52e26" actionBlock:^(UIViewController * _Nonnull vc) {
|
||
OneVC *subvc = [OneVC new];
|
||
subvc.adIndex = 1;
|
||
[vc.navigationController pushViewController:subvc animated:NO];
|
||
}];
|
||
|
||
[[LuxADManager shareInstance] addADWithInterstitialId:@"bee9f7039e56cc7a" actionBlock:^(UIViewController * _Nonnull vc) {
|
||
twoVC *subvc = [twoVC new];
|
||
subvc.adIndex = 2;
|
||
[vc.navigationController pushViewController:subvc animated:NO];
|
||
}];
|
||
|
||
[[LuxADManager shareInstance] addADWithInterstitialId:@"7baed02646413e44" actionBlock:^(UIViewController * _Nonnull vc) {
|
||
threeVC *subvc = [threeVC new];
|
||
subvc.adIndex = 3;
|
||
[vc.navigationController pushViewController:subvc animated:NO];
|
||
}];
|
||
|
||
[[LuxADManager shareInstance] configureADWithAppLovinSDKKey:@"NLQHJDx4rcfd5IqhZf9nad2tIqFSH8SSKP3DXD18sTKUvV6tBfrH9_RPCGb6hvEn3NPXJDmUQCnvnKgHIT7Qn4"];
|
||
__weak typeof(self)weakSelf = self;
|
||
[[LuxADManager shareInstance] showFirstOpenAD:^(NSInteger actionType) {
|
||
[weakSelf configureRootVCWith:window];
|
||
} window:window bgImgName:@"logo" bgColor:nil];
|
||
|
||
|
||
}
|
||
|
||
|
||
#pragma mark -------这个地方配置A面正常的VC
|
||
- (void)configureRootVCWith:(UIWindow *)window {
|
||
|
||
NSString *hasLaunchedBeforeKey = @"hasLaunchedBefore";
|
||
|
||
window.frame = [UIScreen mainScreen].bounds;
|
||
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
|
||
|
||
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
|
||
|
||
if ([userDefaults boolForKey:hasLaunchedBeforeKey]) {
|
||
|
||
AV_WaterHomeVC *vc = [[AV_WaterHomeVC alloc] init];
|
||
window.rootViewController = [[AV_NAVVC alloc] initWithRootViewController:vc];
|
||
|
||
|
||
} else {
|
||
// 第一次启动
|
||
AV_SelectGenderVC *vc = [[AV_SelectGenderVC alloc] init];
|
||
window.rootViewController = [[AV_NAVVC alloc] initWithRootViewController:vc];
|
||
[userDefaults setBool:YES forKey:hasLaunchedBeforeKey];
|
||
NSDate *currentDate = [NSDate date];
|
||
[userDefaults setObject:currentDate forKey:@"savedDate"];
|
||
|
||
}
|
||
|
||
}
|
||
@end
|