123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- //
- // FqToPONSplashAd.m
- // XenonSDK
- //
- // Created by fq on 2021/5/11.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqToPONSplashAd.h"
- #import <AnyThinkSDK/AnyThinkSDK.h>
- #import <AnyThinkSplash/AnyThinkSplash.h>
- #import "XSNetwork.h"
- @interface FqToPONSplashAd()<ATSplashDelegate>
- @property(nonatomic,assign)BOOL isAdReadly;
- @property(nonatomic,strong)void(^splashAdCallback)(BOOL);
- @end
- @implementation FqToPONSplashAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"TopOn"; //平台名称
- self.adUnitId = @"splash";
- self.type = @"splash"; //广告类型
- self.isAdReadly = NO;
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- if ([infos objectForKey:@"topon-splash-unitId"]) {
- self.adUnitId = [infos objectForKey:@"topon-splash-unitId"]; //广告组ID
- }
- //1.程序启动时,加载广告.
- [self loadSplashAdWithPlacementId:self.adUnitId];
- }
- return self;
- }
- //广告是否准备好
- -(BOOL)isAdReadly {
- if ([[ATAdManager sharedManager] splashReadyForPlacementID:self.adUnitId]) {
- return YES;
- } else {
- return NO;
- }
- return NO;
- }
- //用户点击打开广告
- -(void)opensplashAd:(NSString *)adName callback:(void (^)(BOOL))callback {
- if (self.adUnitId.length == 0) {
- NSLog(@"【ToPon广告】,error=开屏广告广告位id为空!!!");
- //[XSNetwork showHudFailure:@"广告位id为空!"];
- return;
- }
- self.adId = adName;
- self.splashAdCallback = callback;
-
- //判断广告是否准备好.
- if([self isAdReadly]){
- //广告准备好,展示广告.
- UIWindow *mainWindow = nil;
- if (@available(iOS 13.0, *)) {
- mainWindow = [UIApplication sharedApplication].windows.firstObject;
- [mainWindow makeKeyWindow];
- }else {
- mainWindow = [UIApplication sharedApplication].keyWindow;
- }
- [[ATAdManager sharedManager] showSplashWithPlacementID:self.adUnitId window:mainWindow delegate:self];
- }else{
- //无广告可展示,加载广告.
- //PS:重新加载广告,考虑一直广告加载失败的情况,超过3次加载广告失败,不做任何处理.不然会死循环.
- [self loadSplashAdWithPlacementId:self.adUnitId];
- [XSNetwork showHudSuccess:@"广告正在加载中"];
- }
- }
- -(void)loadSplashAdWithPlacementId:(NSString *)placementId {
- //containerView:自定义的开屏label
- [[ATAdManager sharedManager] loadADWithPlacementID:placementId extra:@{kATSplashExtraTolerateTimeoutKey:@5.5} delegate:self containerView:nil];
- }
- #pragma mark - ===========ATSplashDelegate============
- - (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
- NSLog(@"Splash Demo: didFinishLoadingADWithPlacementID");
- }
- - (void)didFailToLoadADWithPlacementID:(NSString* )placementID error:(NSError *)error {
- NSLog(@"Splash Demo: failed to load:%@", error);
- self.isAdReadly = NO;
- if(self.splashAdCallback){
- self.splashAdCallback(self.isAdReadly);
- }
- }
- #pragma mark - AT Splash Delegate method(s)
- - (void)splashDidShowForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
- NSLog(@"FqToPONSplashAd.m::splashDidShowForPlacementID:%@ extra:%@", placementID, extra);
- self.isAdReadly = YES;
- if(self.splashAdCallback){
- self.splashAdCallback(self.isAdReadly);
- }
- }
- - (void)splashDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
- NSLog(@"FqToPONSplashAd.m::splashDidClickForPlacementID:%@ extra:%@", placementID, extra);
- }
- - (void)splashDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {
- NSLog(@"FqToPONSplashAd.m::splashDidCloseForPlacementID:%@ extra:%@", placementID, extra);
-
- //广告关闭,重新加载广告.为下次广告展示做准备.
- [self loadSplashAdWithPlacementId:self.adUnitId];
- }
- - (void)splashDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {
- }
- - (void)splashZoomOutViewDidClickForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
- }
- - (void)splashZoomOutViewDidCloseForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
- }
- @end
|