使用 XHLaunchAd 快速实现app启动广告

XHLaunchAd 的 github 代码地址

1. Cocopods导入

pod 'XHLaunchAd'

2. 在 AppDelegate.m 中加入头文件

#import "XHLaunchAd.h"
#import "RTGlobalWebViewViewController.h" // 自己封装的简单浏览器
#import "JKMainNavigationController.h" // 自己写的NavigationController的父类

3. 在 didFinishLaunchingWithOptions 中添加

/** -------------- 广告业务处理 -------------- */
    [self launchAd];

4. 在AppDelegate.m中添加

#pragma mark - 启动广告

- (void)launchAd {

    NSMutableDictionary *dic = [NSMutableDictionary dictionary];

    [[JKNetworkingTool sharedNetworkingTool] postDataWithUrl:@"Reward/getStartUpImg" parameters:dic finishedBlock:^(id responseObj, NSError *error) {
        if (error) {
            return ;
        }

        NSDictionary *dic = [responseObj objectForKey:@"data"];

        XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration new];
        //广告停留时间
        imageAdconfiguration.duration = [dic[@"duration"] integerValue];
        //广告frame
//        imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
        //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
        imageAdconfiguration.imageNameOrURLString = dic[@"img"];
        //网络图片缓存机制(只对网络图片有效)
        imageAdconfiguration.imageOption = XHLaunchAdImageRefreshCached;
        //图片填充模式
        imageAdconfiguration.contentMode = UIViewContentModeScaleToFill;

        if ([dic[@"type"] isEqualToString:@"1"]) {
            //广告点击打开链接
            imageAdconfiguration.openURLString = [NSString stringWithFormat:@"%@Home/Index/activeInfo/b_id/%@",BASE_H5URL,dic[@"b_id"]];
        }

        //广告显示完成动画
        imageAdconfiguration.showFinishAnimate =ShowFinishAnimateFadein;
        //广告显示完成动画时间
        imageAdconfiguration.showFinishAnimate = 0.8;
        //跳过按钮类型
        imageAdconfiguration.skipButtonType = SkipTypeTimeText;
        //后台返回时,是否显示广告
        imageAdconfiguration.showEnterForeground = NO;

        //设置要添加的子视图(可选)
        //imageAdconfiguration.subViews = ...

        //显示图片开屏广告
        [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];

    }];


}

/**
 *  广告点击事件 回调
 */
- (void)xhLaunchAd:(XHLaunchAd *)launchAd clickAndOpenURLString:(NSString *)openURLString;
{
    if(openURLString)
    {
        //跳转到广告详情页面
        RTGlobalWebViewViewController *vc = [[RTGlobalWebViewViewController alloc] init];
        vc.urlString = openURLString;
        vc.navTitle = @"广告";
        vc.isFromLaunchAd = YES;
        JKMainNavigationController *nav = [[JKMainNavigationController alloc] initWithRootViewController:vc];
        [self.window.rootViewController presentViewController:nav animated:YES completion:nil];

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值