XHLaunchAd 的 github 代码地址
1. Cocopods导入
pod 'XHLaunchAd'
2. 在 AppDelegate.m 中加入头文件
#import "XHLaunchAd.h"
#import "RTGlobalWebViewViewController.h"
#import "JKMainNavigationController.h"
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];
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;
[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];
}
}