美文网首页 ios零碎记录00『 基础知识 』Ios
[iOS] - JWLaunchAd,一行代码集成启动页广告.

[iOS] - JWLaunchAd,一行代码集成启动页广告.

作者: SwiftBest | 来源:发表于2016-09-09 09:23 被阅读370次

获取最新版本Github

| | |

----|------|-------|

演示项目

API

/**
  *     初始化启动页 
  *
  *     @param adDuration 停留时间
  *     @param hideSkip 是否隐藏跳过 
  *     @param setLaunchAd launchAdView 
  *
  *     @return self 
  */
+ (instancetype)initImageWithAttribute:(NSInteger)adDuration showSkipType:(SkipShowType)showSkipType setLaunchAd:(JWSetLaunchAdBlock)setLaunchAd;

/** 
  *     设置图片 
  * 
  *     @param strURL URL 
  *     @param options 图片缓冲模式 
  *     @param result UIImage *image, NSURL *url 
  *     @param adClickBlock 点击图片回调 
  */
- (void)setWebImageWithURL:(NSString *)strURL options:(JWWebImageOptions)options result:(JWWebImageCompletionBlock)result adClickBlock:(JWLaunchAdClickBlock)adClickBlock;

 /**
   *     设置动画跳过属性
   *
   *     @param strokeColor 转动颜色
   *     @param lineWidth 宽度
   *     @param backgroundColor 背景色
   *     @param textColor 字体颜色
   */
- (void)setAnimationSkipWithAttribute:(UIColor *)strokeColor lineWidth:(NSInteger)lineWidth backgroundColor:(UIColor *)backgroundColor textColor:(UIColor *)textColor;

/** 
  *     广告图Frame 
  */
@property (assign, nonatomic) CGRect launchAdViewFrame;

使用

在AppDelegate中设置Window.rootViewController之后调用下面方法:

// 1.设置启动页广告图片的URL
NSString *imgUrlString =@"http://imgstore.cdn.sogou.com/app/a/100540002/714860.jpg";

// 2.初始化启动页
[JWLaunchAd initImageWithAttribute:6.0 showSkipType:SkipShowTypeAnimation setLaunchAd:^(JWLaunchAd *launchAd) { 
     __block JWLaunchAd *weakSelf = launchAd; 

    //如果选择 SkipShowTypeAnimation 需要设置动画跳过按钮的属性 
    [weakSelf setAnimationSkipWithAttribute:[UIColor redColor] lineWidth:3.0 backgroundColor:nil textColor:nil]; 

    [launchAd setWebImageWithURL:imgUrlString options:JWWebImageDefault result:^(UIImage *image, NSURL *url) { 

         // 异步缓冲图片完成后调整图片Frame 
        weakSelf.launchAdViewFrame = CGRectMake(0, 0, kScreen_Width, kScreen_Height-100); 
    }adClickBlock:^{ 

        // 3.广告回调  
        NSString *url = @"https://www.baidu.com"; 
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
     }];
 }];

安装

 //CocoaPods
 1. 在Podfile添加 pod 'JWLaunchAd'.
 2. 运行 pod install 或 pod update.
 3. import "JWLaunchAd.h".

//手动安装
 1. 将JWLaunchAd导入你的Xcode项目.
 2. import "JWLaunchAd.h".

许可证

JWLaunchAd MIT许可下提供。有关详细信息,请参阅许可文件。

相关文章

网友评论

  • MrCoolHao:我下载最新的也是这个问题,先闪出根视图,又出现的广告,谁知道怎么改
  • 南京老侉子:我也遇到了问题,,启动图总是会先闪出根视图,再出现广告图
  • 口水电影:如果图片URL是通过afn请求得到的,启动图总是会先闪出根视图,再出现广告图,不知道怎么解决,
    无心落残梦:我在appdelegate里面请求网上的图片,然后就不走方法了,这个是什么情况啊
    口水电影:-(void)addInWindow{
    //监测DidFinished通知
    [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
    //等DidFinished方法结束后,将其添加至window上(不然会检测是否有rootViewController)
    //阻塞当前线程,跟新主线程UI
    [[[UIApplication sharedApplication].delegate window] performSelectorOnMainThread:@selector(addSubview:) withObject:self waitUntilDone:YES];

    //dispatch_async(dispatch_get_main_queue(), ^{
    //[[[UIApplication sharedApplication].delegate window] addSubview:self];
    //});
    }];
    }
    已解决,原本异步加载的改为线程阻塞

本文标题:[iOS] - JWLaunchAd,一行代码集成启动页广告.

本文链接:https://www.haomeiwen.com/subject/mjseettx.html