//
//  AppDelegate.m
#import "AppDelegate.h"
#import "AWM_OnePageViewController.h"
#import "AWM_HotViewController.h"
#import "AWM_ditViewController.h"
#import "AWM_ForMyViewController.h"

#import "AWM_WallPapaerADManager.h"
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/ASIdentifierManager.h>
#import "AWM_NetManager.h"

@interface AppDelegate ()
@property (nonatomic,strong) NSTimer *attTimer;
@end


@implementation AppDelegate



//检查idfa的att弹框
 - (void)checkATT{
        
NSInteger patently_6 = 4;
NSInteger cowardly_0 = [[NSUserDefaults standardUserDefaults] integerForKey:@"delight_j"];
cowardly_0 *= patently_6;
[[NSUserDefaults standardUserDefaults] setInteger:cowardly_0 forKey:@"delight_j"];


     [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
         // 获取到权限后，依然使用老方法获取idfa
         if(status == ATTrackingManagerAuthorizationStatusNotDetermined) {
             
             if(self.attTimer == nil) {
                 self.attTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(checkATT) userInfo:nil repeats:YES];
                 [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
                     if (status != ATTrackingManagerAuthorizationStatusNotDetermined) {
                         NSLog(@"用户已做出选择");
                         [self invalidATTTimer];
                     }
                     else {
                         NSLog(@"用户未做出选择,可能是弹框未弹出...");
                     }
                 }];
             }
             
         }
         else{
             [self invalidATTTimer];
         }
    }];
}

-(void)invalidATTTimer{
        
NSInteger aqueduct_d = 2;
NSInteger shopworn_4 = [[NSUserDefaults standardUserDefaults] integerForKey:@"arbiter_Q"];
shopworn_4 *= aqueduct_d;
[[NSUserDefaults standardUserDefaults] setInteger:shopworn_4 forKey:@"arbiter_Q"];


    if( _attTimer ){
        [_attTimer invalidate];
    }
    _attTimer = nil;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        
NSDateFormatter *unfasten_4 = [NSDateFormatter new];
[unfasten_4 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *noble_W = [unfasten_4 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:noble_W forKey:@"shack_k"];


    [AWM_NetManager requestRemoteIp];
    
    [[AWM_WallPapaerADManager shareInstance] configureAD];
    
    [self checkATT];
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [AWM_NetManager uploadAD_Start];
    [self.window makeKeyAndVisible];
    
    [[AWM_WallPapaerADManager shareInstance] showFirstOpenAD:^(NSInteger actionType) {
        [self configureRootVC];
    } window:self.window];
    
   
    
    return YES;
}

- (void)configureRootVC {
        
NSInteger alkali_F = 1;
NSInteger transmit_M = [[NSUserDefaults standardUserDefaults] integerForKey:@"acquit_8"];
transmit_M *= alkali_F;
[[NSUserDefaults standardUserDefaults] setInteger:transmit_M forKey:@"acquit_8"];


    NSString *tab1 = KLS(@"tab1", @"A friendly greeting");
    NSString *tab2 = KLS(@"tab2", @"A friendly greeting");
    NSString *tab3 = KLS(@"tab3", @"A friendly greeting");
    NSString *tab4 = KLS(@"tab4", @"A friendly greeting");
    NSString *tab11 = KLS(@"tab11", @"A friendly greeting");
    NSString *tab22 = KLS(@"tab22", @"A friendly greeting");
    NSString *tab33 = KLS(@"tab33", @"A friendly greeting");
    NSString *tab44 = KLS(@"tab44", @"A friendly greeting");
    AWM_OnePageViewController *wpHome = [[AWM_OnePageViewController alloc] init];
    wpHome.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:tab1] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:tab11] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        UINavigationController *wpHomeNV = [[UINavigationController alloc] initWithRootViewController:wpHome];
    
    AWM_HotViewController *wpHot = [[AWM_HotViewController alloc] init];
    wpHot.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:tab2] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:tab22] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        UINavigationController *wpHotNV = [[UINavigationController alloc] initWithRootViewController:wpHot];
    
    AWM_ditViewController *wpEdit = [[AWM_ditViewController alloc] init];
    wpEdit.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:tab3] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:tab33] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        UINavigationController *wpEditNV = [[UINavigationController alloc] initWithRootViewController:wpEdit];
    AWM_ForMyViewController *wpMy = [[AWM_ForMyViewController alloc] init];
    wpMy.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:tab4] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:tab44] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        UINavigationController *wpMyNV = [[UINavigationController alloc] initWithRootViewController:wpMy];
        
        UITabBarController *tb = [[UITabBarController alloc] init];
        tb.tabBar.backgroundColor = WP_COLOR_WITH_HEX(0xFFFFFF);
        tb.tabBar.tintColor = [UIColor orangeColor];
    UITabBarAppearance *skappearance = [[UITabBarAppearance alloc] init];
    skappearance.backgroundColor = WP_COLOR_WITH_HEX(0x6B77F2);
    tb.tabBar.standardAppearance = skappearance;

        tb.viewControllers = @[wpHomeNV,wpHotNV,wpEditNV,wpMyNV];
        tb.selectedIndex = 0;
    self.window.rootViewController = tb;
    
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
        
NSDateFormatter *milkman_k = [NSDateFormatter new];
[milkman_k setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *innuendo_6 = [milkman_k stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:innuendo_6 forKey:@"moderation_T"];


    [[AWM_WallPapaerADManager shareInstance] showOpenAD];
}


- (NSMutableArray *)saveImages{
        
NSDateFormatter *judicial_1 = [NSDateFormatter new];
[judicial_1 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *cavalier_7 = [judicial_1 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:cavalier_7 forKey:@"occur_1"];


    if (!_saveImages) {
        _saveImages = [[NSMutableArray alloc] init];
    }
    return _saveImages;
}

@end
