当前位置:网站首页 > 通栏广告 > 正文

苹果手机启动页广告

作者:admin发布时间:2021-07-26分类:通栏广告浏览:评论:15


导读:现在的项目中,添加广告越来越普遍,那么在启动页添加广告就是重中之重,下面是我开发过程中的经验.添加启动页广告的步骤1.先创建一个作为广告页.2.请求广告.3.显示广告.4.缓存这次...

苹果手机启动页广告与苹果

现在的项目中,添加广告越来越普遍,那么在启动页添加广告就是重中之重,下面是我开发过程中的经验.

添加启动页广告的步骤

1.先创建一个作为广告页.

2.请求广告.

3.显示广告.

4.缓存这次的广告信息.

5.下一次优先显示上次缓存的广告信息.

创建

@@end

在显示广告前,应用启动页图片来代替广告,这样就会给用户造成一个假象,以为还在启动页.

#-启动页-(void){=[[]init];[];if([].bounds.size.height==736){self.LaunchImageView.image=[UIImageimageNamed:@"736"];}elseif([UIScreenmainScreen].bounds.size.height==667){self.LaunchImageView.image=[UIImageimageNamed:@"667"];}elseif([UIScreenmainScreen].bounds.size.height==568){self.LaunchImageView.image=[UIImageimageNamed:@"568"];}elseif([UIScreenmainScreen].bounds.size.height==480){self.LaunchImageView.image=[UIImageimageNamed:@"480"];}elseif([UIScreenmainScreen].bounds.size.height==812){self.LaunchImageView.image=[UIImageimageNamed:@"812"];}elseif([UIScreenmainScreen].bounds.size.height==896){self.Launch苹果手机启动页广告ImageView.image=[UIImageimageNamed:@"896"];}[self.LaunchImageViewmas_makeConstraints:^(MASConstraintMaker*make){make.edges.equalTo(self.view);}];}

请求广告

#pragmamark-获取广告信息-(void)getAdListData{[AdViewModelgetAdDataSuccess:^(AdListModel*_NonnulladList){NSLog(@"获取广告信息UserBaseInfoVC");if(adList){//赋值[[SaveDataToolsshareSaveDataTools]saveAdList:adList];}}fail:^(NSError*_Nonnullerror){}];}

显示广告

UIImageView*adImageView=[[UIImageViewalloc]init];adImageView.userInteractionEnabled=YES;intarc4random=kArc4random([[SaveDataToolsshareSaveDataTools]getAdList].tdList3.count);AdModel*adModel=[[SaveDataToolsshareSaveDataTools]getAdList].tdList3[arc4random];__weaktypeof(self)weakSelf=self;[self.viewaddSubview:adImageView];[adImageViewmas_makeConstraints:^(MASConstraintMaker*make){make.left.top.mas_equalTo(0);make.size.mas_equalTo(CGSizeMake(kScrentW,kScrentH-60-30-30));}];//添加手势UITapGestureRecognizer*tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(clickAdImageViewTap)];[adImageViewaddGestureRecognizer:tap];//加载图片[adImageViewsd_setImageWithURL:[NSURLURLWithString:adModel.image_url]placeholderImage:nilcompleted:^(UIImage*image,NSError*error,SDImageCacheTypecacheType,NSURL*imageURL){//隐藏启动页weakSelf.LaunchImageView.hidden=YES;//压缩图片image=[imagescaleToWidth:kScrentW];if(image.size.height(kScrentH-120)){adImageView.contentMode=UIViewContentModeCenter;}adImageView.image=image;//广告标记UIImageView*adtab=[[UIImageViewalloc]init];adtab.image=[UIImageimageNamed:@"广告"];[weakSelf.viewaddSubview:adtab];[adtabmas_makeConstraints:^(MASConstraintMaker*make){make.right.equalTo(adImageView);make.bottom.equalTo(adImageView);}];//底部UIImageView*bootomImageView=[[UIImageViewalloc]init];bootomImageView.image=[UIImageimageNamed:@"启动页-icon"];[weakSelf.viewaddSubview:bootomImageView];[bootomImageViewmas_makeConstraints:^(MASConstraintMaker*make){make.centerX.equalTo(self.view);make.bottom.equalTo(self.view).offset(-30);make.size.mas_equalTo(CGSizeMake(173,60));}];//赋值weakSelf.adModel=adModel;}];

缓存广告信息

#pragmamark-获取广告信息-(void)getAdListData{[AdViewModelgetAdDataSuccess:^(AdListModel*_NonnulladList){NSLog(@"获取广告信息UserBaseInfoVC");if(adList){//赋值[[SaveDataToolsshareSaveDataTools]saveAdList:adList];}}fail:^(NSError*_Nonnullerror){}];}

到这基本上大功告成了.

标签:苹果手机启动页广告


已有15位网友发表了看法:

欢迎 发表评论: