Code Monkey home page Code Monkey logo

launchad's Introduction

LaunchAD

两行代码添加iOS应用启动广告的功能,支持无网络显示,可点击进入广告页面。

广告思路:第一次进入app时没有广告(因为广告的加载最好是从本地缓存获取,如果每次都从网络获取有可能因网速原因加载失败)。第一次启动的同时,根据后台返回的数据加载广告(一般是图片地址和广告链接),然后保存在本地。第二次启动的时候本地存在了广告,这个时候就可以显示了。然后请求最新的广告数据,如果和旧广告一样则不做操作;如果有新广告,则删除本地的旧广告,保存新广告,下次启动再显示。

image
使用方法: 在使用的地方导入头文件ADView.h之后,添加如下代码

NSString *imageUrl = @"http://img5q.duitang.com/uploads/item/201505/25/20150525223238_NdQrh.thumb.700_0.png";
NSString *adURL = @"http://tieba.baidu.com/";

//1、创建广告
ADView *adView = [[ADView alloc] initWithFrame:[UIApplication sharedApplication].keyWindow.bounds andImgUrl:imageUrl andADUrl:adURL andClickBlock:^(NSString *clikImgUrl) {
    
    NSLog(@"进入广告:%@",clikImgUrl);
}];

//2、显示广告
[adView show];

launchad's People

Contributors

xiongoahc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

launchad's Issues

应该将下载新图片,删除旧图片,放到广告倒计时结束之后

否则会出现,更换图片地址,出现已经把旧的图片删除的情况,这时候还使用缓存就会找不到文件页面黑屏。

  • (void)show
    {
    //判断本地缓存广告是否存在,存在即显示
    if ([self imageExist]) {
    //设置按钮倒计时
    [_countBtn setTitle:[NSString stringWithFormat:@"跳过%zd", self.showTime] forState:UIControlStateNormal];
    //当前显示的广告图片
    _adView.image = [UIImage imageWithContentsOfFile:_imgPath];
    //当前显示的广告链接
    _clickAdUrl = [UserDefaults valueForKey:adUrl];
    //开启倒计时
    [self startTimer];
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:self];
    }else{
    //不管本地是否存在广告图片都获取最新图片
    [self setNewADImgUrl:_imgUrl];
    }
    }

  • (void)dismiss
    {
    [self.countTimer invalidate];
    self.countTimer = nil;

    [UIView animateWithDuration:0.1f animations:^{

      self.alpha = 0.f;
    

    } completion:^(BOOL finished) {

      [self removeFromSuperview];
      //不管本地是否存在广告图片都获取最新图片
      [self setNewADImgUrl:_imgUrl];
    

    }];
    }
    这里面解决了这个问题。

广告可能要更改怎么办

比如我要用七牛的云,指定image为a.png,过段时间我想用b.png,我该怎么改,服务器端将b.png改为a.png,那图片虽然是同一名字,但是客户端如何判断呢,可不可以写个方法判断一下呢?

自问自答:千万不要把代码放到AppDelegate或者UITabBarController里!!!

自作聪明把代码放到AppDelegate里(作者明明说随便放到那里的呀),结果app界面先铺出来,然后广告页才出来,中间间隔了0.2秒,特别恶心。后来打断点才发现,AppDelegate或者UITabBarController里的非系统方法都是异步执行,目的应该是为了加速app的启动速度吧。总之不要自作聪明把代码放到AppDelegate或者UITabBarController里,老老实实放到app的第一个controller里!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.