admin 管理员组文章数量: 1184232
使用 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];}
}
本文标签: 使用 XHLaunchAd 快速实现app启动广告
版权声明:本文标题:使用 XHLaunchAd 快速实现app启动广告 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.roclinux.cn/b/1693762700a241368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论