123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- //
- // FqToPONInterstitialAd.m
- // XenonSDK
- //
- // Created by fq on 2021/5/11.
- // Copyright © 2021 SAGESSE. All rights reserved.
- //
- #import "FqToPONInterstitialAd.h"
- #import <AnyThinkInterstitial/AnyThinkInterstitial.h>
- #import "XSNetwork.h"
- #import "GMTools.h"
- @interface FqToPONInterstitialAd()<ATInterstitialDelegate>
- @property(nonatomic,assign)BOOL isAdReadly;
- @property(nonatomic,strong)void(^InterstitialAdCallback)(BOOL);
- @end
- @implementation FqToPONInterstitialAd
- -(instancetype)init{
- if (self = [super init]) {
- self.agentName = @"TopOn"; //平台名称
- self.adUnitId = @"Interstitial";
- self.type = @"Interstitial"; //广告类型
- self.isAdReadly = NO;
- NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
- if ([infos objectForKey:@"topon-Interstitial-unitId"]) {
- self.adUnitId = [infos objectForKey:@"topon-Interstitial-unitId"]; //广告组ID
- }
-
- //1.程序启动时,加载广告.
- [self loadInterstitialAdWithPlacementId:self.adUnitId];
- }
- return self;
- }
- //广告是否准备好
- -(BOOL)isAdReadly {
- if ([[ATAdManager sharedManager] interstitialReadyForPlacementID:self.adUnitId]) {
- return YES;
- } else {
- return NO;
- }
- return NO;
- }
- //打开广告
- -(void)openInterstitialAd:(NSString *)adName callback:(void (^)(BOOL))callback {
- if (self.adUnitId.length == 0) {
- NSLog(@"【ToPon广告】,error=插屏广告广告位id为空!!!");
- [XSNetwork showHudFailure:@"广告位id为空!"];
- return;
- }
- self.adId = adName;
- self.InterstitialAdCallback = callback;
-
- //判断广告是否准备好.
- if([self isAdReadly]){
- //广告准备好,展示广告.
- UIViewController *vc = [GMTools getViewControl];
- [[ATAdManager sharedManager] showInterstitialWithPlacementID:self.adUnitId inViewController:vc delegate:self];
- }else{
- //无广告可展示,加载广告.
- //PS:重新加载广告,考虑一直广告加载失败的情况,超过3次加载广告失败,不做任何处理.不然会死循环.
- [self loadInterstitialAdWithPlacementId:self.adUnitId];
- [XSNetwork showHudSuccess:@"广告正在加载中"];
- }
- }
- //加载广告资源
- -(void)loadInterstitialAdWithPlacementId:(NSString *)placementId {
- [[ATAdManager sharedManager] loadADWithPlacementID:self.adUnitId extra:nil delegate:self];
-
- }
- #pragma mark - ===========ATInterstitialDelegate=============
- -(void) didFinishLoadingADWithPlacementID:(NSString *)placementID {
- NSLog(@"Interstitial Demo: didFinishLoadingADWithPlacementID");
-
- }
- -(void) didFailToLoadADWithPlacementID:(NSString* )placementID error:(NSError *)error {
- NSLog(@"Interstitial Demo: failed to load:%@", error);
- self.isAdReadly = NO;
- if(self.InterstitialAdCallback){
- self.InterstitialAdCallback(self.isAdReadly);
- }
- }
- -(void) interstitialDidShowForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidShowForPlacementID:%@ extra:%@", placementID, extra);
-
- self.isAdReadly = YES;
- if(self.InterstitialAdCallback){
- self.InterstitialAdCallback(self.isAdReadly);
- }
- }
- -(void) interstitialFailedToShowForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialFailedToShowForPlacementID:%@ error:%@ extra:%@", placementID, error, extra);
- }
- -(void) interstitialDidFailToPlayVideoForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidFailToPlayVideoForPlacementID:%@ error:%@ extra:%@", placementID, error, extra);
- }
- -(void) interstitialDidStartPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidStartPlayingVideoForPlacementID:%@ extra:%@", placementID, extra);
- }
- -(void) interstitialDidEndPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidEndPlayingVideoForPlacementID:%@ extra:%@", placementID, extra);
- }
- -(void) interstitialDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidCloseForPlacementID:%@ extra:%@", placementID, extra);
-
- //广告关闭,重新加载广告.为下次广告展示做准备.
- [self loadInterstitialAdWithPlacementId:self.adUnitId];
-
- }
- -(void) interstitialDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidClickForPlacementID:%@ extra:%@", placementID, extra);
- }
- -(void) interstitialDeepLinkOrJumpForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra result:(BOOL)success {
- NSLog(@"FqToPONInterstitialAd.m::interstitialDidClickForPlacementID:%@ extra:%@ success:%@", placementID, extra,success? @"YES":@"NO");
- }
- @end
|