InterstitialVC.m
in DemoThe extra dictionary in this step supports passing in relevant parameters for configuring ads and your custom parameters. You can view more information about extra parameters here.
// Import header file
#import <AnyThinkInterstitial/AnyThinkInterstitial.h>
@interface InterstitialVC () <ATAdLoadingDelegate, ATInterstitialDelegate>
@property (nonatomic, assign) NSInteger retryAttempt; // Retry attempt counter
@end
@implementation InterstitialVC
// Placement ID
#define InterstitialPlacementID @"b680a1e0ae7a43"
// Scene ID, optional, can be generated in the backend. Pass empty string if not available
#define InterstitialSceneID @""
#pragma mark - Load Ad
/// Load ad button clicked
- (void)loadAd {
NSMutableDictionary * loadConfigDict = [NSMutableDictionary dictionary];
// Optional integration, set loading pass-through parameters
[loadConfigDict setValue:@"media_val_InterstitialVC" forKey:kATAdLoadingExtraMediaExtraKey];
[[ATAdManager sharedManager] loadADWithPlacementID:InterstitialPlacementID extra:loadConfigDict delegate:self];
}
/// Ad placement loading completed
/// - Parameter placementID: Placement ID
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
// Reset retry count
self.retryAttempt = 0;
}
/// Ad placement loading failed
/// - Parameters:
/// - placementID: Placement ID
/// - error: Error information
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
if (self.retryAttempt >= 3) {
return;
}
self.retryAttempt++;
// Calculate delay time: power of 2, maximum 8 seconds
NSInteger delaySec = pow(2, MIN(3, self.retryAttempt));
// Delayed retry loading ad
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadAd];
});
}
- If you need to display ads in the loading success callback (didFinishLoadingADWithPlacementID:), to avoid ads not displaying properly, please ensure the current app is in the foreground before calling the display method.
- Scene reach rate statistics, displayed in the backend's Data Reports -> Funnel Analysis Report -> Reach Ad Scene, called before displaying ads.
#pragma mark - Show Ad
/// Display ad
- (void)showAd {
// Scene statistics function, displayed in the backend's Data Reports -> Funnel Analysis Report -> Reach Ad Scene, called before displaying ads. Optional integration
[[ATAdManager sharedManager] entryInterstitialScenarioWithPlacementID:InterstitialPlacementID scene:InterstitialSceneID];
// Check if ready
if (![[ATAdManager sharedManager] interstitialReadyForPlacementID:InterstitialPlacementID]) {
[self loadAd];
return;
}
// Display configuration, Scene passes in the backend scene ID, pass empty string if not available, showCustomExt parameter can pass in custom parameter string
ATShowConfig *config = [[ATShowConfig alloc] initWithScene:InterstitialSceneID showCustomExt:@"testShowCustomExt"];
// Display ad
// For fullscreen interstitials, inViewController can pass in the root controller, such as tabbarController or navigationController, to let the ad cover the tabbar or navigationBar
[[ATAdManager sharedManager] showInterstitialWithPlacementID:InterstitialPlacementID
showConfig:config
inViewController:self
delegate:self
nativeMixViewBlock:nil];
}
/// Got display revenue
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)didRevenueForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Ad has been displayed
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)interstitialDidShowForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Ad display failed
/// - Parameters:
/// - placementID: Placement ID
/// - error: Error information
/// - extra: Extra information dictionary
- (void)interstitialFailedToShowForPlacementID:(NSString *)placementID error:(NSError *)error extra:(NSDictionary *)extra {
}
/// Video playback failed
/// - Parameters:
/// - placementID: Placement ID
/// - error: Error information
/// - extra: Extra information dictionary
- (void)interstitialDidFailToPlayVideoForPlacementID:(NSString *)placementID error:(NSError *)error extra:(NSDictionary *)extra {
// Preload next ad
[self loadAd];
}
/// Video started playing
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)interstitialDidStartPlayingVideoForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Video finished playing
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)interstitialDidEndPlayingVideoForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
/// Ad has been closed
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)interstitialDidCloseForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
// Preload next ad
[self loadAd];
}
/// Ad has been clicked (redirected)
/// - Parameters:
/// - placementID: Placement ID
/// - extra: Extra information dictionary
- (void)interstitialDidClickForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
}
Fully automatic loading : TopOn has launched a one-stop solution that intelligently determines the timing for preloading and caching the next ad based on the user's usage status and the progress of ad consumption.