2021-08-31 ios启动页

//

//  SMMActivityPageVC.m

//  AgentApp

//

//  Created by Apple on 2021/8/26.

//  Copyright © 2021 YDSuperMarket. All rights reserved.

//

#import "SMMActivityPageVC.h"

#import "YDSinglePhotoRequest.h"

#import "AppDelegate.h"

#import

@interface SMMActivityPageVC ()

{

    UIButton* _mycountButton;

    NSInteger_startNum ;

}

@property (nonatomic,strong)NSTimer * timer ;

/** 图片路径*/

@property (nonatomic, copy) NSString *filePath;

@property (nonatomic,strong)UIImageView * LaunchImageView ;

@property (nonatomic,strong) NSDictionary *adInfoDic;

@end

@implementation SMMActivityPageVC

- (void)viewDidLoad {

    [superviewDidLoad];

    [selfsetScreenForLauchScreen];

    _startNum =3;

}

#pragma mark- 启动页

- (void)setScreenForLauchScreen

{

    self.LaunchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, YDWidth, YDHeight)];

    [self.view addSubview:self.LaunchImageView];

    self.LaunchImageView.contentMode = UIViewContentModeScaleAspectFill;

    self.LaunchImageView.image = [UIImage imageNamed:@"闪屏_韵达超市"];

    UIButton *bgBtn = [UIButton buttonWithType:UIButtonTypeCustom];

    [bgBtn addTarget:selfaction:@selector(tapClick) forControlEvents:UIControlEventTouchUpInside];

    bgBtn.frame = CGRectMake(0,0, YDWidth, YDHeight);

    [self.view addSubview:bgBtn];

    __weaktypeof(self) weakSelf =self;

    //切换新的 图片

    [selfloadADViewSuccess:^(id  _Nullablejson) {

        if([json isKindOfClass:[NSDictionary class]]) {

            NSDictionary *dic = (NSDictionary *)json;

            NSString *showTime = [[dic yd_objectForKey:@"showTime"] isExist]?[dic yd_objectForKey:@"showTime"]:@"3";

            _startNum = [showTime integerValue];

            NSString *urlStr = [dic yd_objectForKey:@"image"];

            if(urlStr.length <=0) {

                [weakSelf countBtnClick:_mycountButton];

                return;

            }

            //通知跳转的广告信息

            weakSelf.adInfoDic = [NSDictionary dictionaryWithDictionary:dic];


            // 1.判断沙盒中是否存在广告图片,如果存在,直接显示

            NSURL *imageUrl = [NSURL URLWithString:urlStr];

            UIImage *cacheImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:urlStr];

            if(cacheImage) {

                YDLog(@"cacheImage");

                /**显示广告图 */

                weakSelf.LaunchImageView.image  = cacheImage;

            }else{

                NSLog(@"noCacheImage");

                SDWebImageManager *manager = [SDWebImageManager sharedManager];

                [manager loadImageWithURL:imageUrl options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL *_NullabletargetURL) {


                } completed:^(UIImage *_Nullableimage, NSData *_Nullabledata, NSError *_Nullableerror, SDImageCacheType cacheType,BOOLfinished, NSURL *_NullableimageURL) {

                    if(image && finished && error ==nil) {

                        weakSelf.LaunchImageView.image  = image;

                        [[SDImageCache sharedImageCache] storeImage:image forKey:urlStr completion:^{

                            nil;

                        }];

                    }

                }];

            }


            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1* NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                [_timer setFireDate:[NSDate distantPast]];

            });


            UIButton * countButton = [UIButton buttonWithType:UIButtonTypeCustom];

            [countButton setFrame:CGRectMake(YDWidth -15-100,40,100,30)];

            countButton.backgroundColor = [UIColor clearColor] ;

            [countButton setTitleColor:[UIColor blackColor] forState:0];

            countButton.titleLabel.font = [UIFont systemFontOfSize:15] ;

            countButton.layer.cornerRadius =15;

            countButton.layer.borderWidth =0.5f;

            countButton.layer.borderColor = [UIColor blackColor].CGColor ;

            [countButton addTarget:selfaction:@selector(countBtnClick:) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:countButton];

            _mycountButton = countButton ;



            if(!_timer) {

                _timer = [NSTimer scheduledTimerWithTimeInterval:1.0ftarget:selfselector:@selector(timerStart) userInfo:nilrepeats:YES];

                [_timer setFireDate:[NSDate distantFuture]];

                [[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSRunLoopCommonModes];

            }


        }

    } failure:^(NSString *_NonnullerrorMSG) {

        //失败 立即跳转

        [weakSelf countBtnClick:_mycountButton];

    }];

}

#pragma mark  ======广告页面======

-(void)loadADViewSuccess:(nullableSuccess)successfailure:(nullableFailure)failure

{



    __blockBOOLnetTimeOutTwoSes =NO;

    [YDSinglePhotoRequest postResult:[NSString stringWithFormat:@"%@%@",UPLoadBaseURL,@"/shuffling/queryFirstPic"] params:@{@"pageNum":@"1",

                                                                                                                            @"pageSize":@"10",@"picType":@"2"}  success:^(idjson) {

        NSDictionary*body = (NSDictionary*)json;;

        BOOLresult = [[bodyyd_objectForKey:@"result"]boolValue];

        if(result)

        {

            iddata = [bodyyd_objectForKey:@"data"];

            if([[datayd_objectForKey:@"rows"]isExist])

            {

                NSArray*dataArr = [datayd_objectForKey:@"rows"];

                if(dataArr.count!=0) {

                    NSDictionary*dict = [datayd_objectForKey:@"rows"][0];


                    if(!netTimeOutTwoSes) {

                        //没有超过2秒

                        netTimeOutTwoSes =YES;

                        success(dict);

                    }

                    else

                    {

                        //超过2秒

                        failure(@"超过2秒");

                    }


                }else

                {

                    failure(@"数组为空");

                }

            }else

            {

                failure(@"row不存在");

            }

        }

    }failure:^(NSError*error) {

        if(!netTimeOutTwoSes) {

            //没有超过2秒

            netTimeOutTwoSes =YES;

            failure(@"网络连接失败");

        }

        else

        {

            //超过2秒

            failure(@"超过2秒");

        }

    }];

    //2秒后没有网络回调,立即改变跟控制器

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        if(!netTimeOutTwoSes) {

            netTimeOutTwoSes =YES;

            failure(@"超过2秒");

        }

    });

}

- (void)countBtnClick:(UIButton*)btn{

    [_timer invalidate];

    _timer=nil;

    [self changeRootVC];

}

- (void)tapClick{

    [_timer invalidate];

    _timer=nil;

    [self changeRootVCAndOpenWebVC];

}

- (void)timerStart{

    _startNum-- ;

    [_mycountButton setTitle:[NSString stringWithFormat:@"跳过 %ld秒",(long)_startNum] forState:0];

    NSLog(@"_startNum-%d",_startNum) ;

    if(_startNum==0) {

        [_timerinvalidate];

        _timer=nil;


        [selfchangeRootVC];

    }

}

- (void)changeRootVC

{

    [[AppDelegate sharedAppDelegate].window changeViewController];

}

-(void)changeRootVCAndOpenWebVC

{

    [[AppDelegate sharedAppDelegate].window changeViewController];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [[NSNotificationCenter defaultCenter] postNotificationName:@"pushtoad" object:nil userInfo:self.adInfoDic];

    });


}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/

@end

你可能感兴趣的:(2021-08-31 ios启动页)