Interstitial Ads
Integrate CloudX interstitial ads in iOS apps
@interface YourViewController () <CLXInterstitialDelegate, CLXAdRevenueDelegate>
@property (nonatomic, strong) CLXInterstitial *interstitialAd;
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation YourViewController
- (void)createInterstitialAd {
self.interstitialAd = [[CloudXCore shared] createInterstitialWithAdUnitId:@"your-interstitial-ad-unit-id"];
self.interstitialAd.delegate = self;
self.interstitialAd.revenueDelegate = self;
[self.interstitialAd load];
}
- (void)showInterstitialAd {
if (self.interstitialAd.isReady) {
// Basic show
[self.interstitialAd showFromViewController:self];
// Or with optional placement and custom data for tracking
// [self.interstitialAd showFromViewController:self placement:@"level_complete" customData:@"level:5,score:1000"];
} else {
NSLog(@"Interstitial ad not ready");
}
}
- (void)dealloc {
[self.interstitialAd destroy];
}
#pragma mark - CLXInterstitialDelegate
- (void)didLoadAd:(CLXAd *)ad {
NSLog(@"Interstitial ad loaded from %@", ad.networkName);
self.retryAttempt = 0;
}
- (void)didFailToLoadAd:(NSString *)adUnitId error:(CLXError *)error {
NSLog(@"Interstitial ad failed to load: %@", error.localizedDescription);
self.retryAttempt++;
NSTimeInterval delay = pow(2.0, MIN(5, self.retryAttempt));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.interstitialAd load];
});
}
- (void)didDisplayAd:(CLXAd *)ad {
NSLog(@"Interstitial ad displayed");
}
- (void)didFailToDisplayAd:(CLXAd *)ad error:(CLXError *)error {
NSLog(@"Interstitial ad failed to display: %@", error.localizedDescription);
[self.interstitialAd load];
}
- (void)didHideAd:(CLXAd *)ad {
NSLog(@"Interstitial ad hidden");
[self.interstitialAd load]; // Reload for next use
}
- (void)didClickAd:(CLXAd *)ad {
NSLog(@"Interstitial ad clicked");
}
#pragma mark - CLXAdRevenueDelegate
- (void)didPayRevenueForAd:(CLXAd *)ad {
NSLog(@"Interstitial revenue: %@ from %@", ad.revenue, ad.networkName);
}
@endclass YourViewController: UIViewController, CLXInterstitialDelegate, CLXAdRevenueDelegate {
private var interstitialAd: CLXInterstitial?
private var retryAttempt = 0
func createInterstitialAd() {
interstitialAd = CloudXCore.shared.createInterstitial(adUnitId: "your-interstitial-ad-unit-id")
interstitialAd?.delegate = self
interstitialAd?.revenueDelegate = self
interstitialAd?.load()
}
func showInterstitialAd() {
if interstitialAd?.isReady == true {
// Basic show
interstitialAd?.show(from: self)
// Or with optional placement and custom data for tracking
// interstitialAd?.show(from: self, placement: "level_complete", customData: "level:5,score:1000")
} else {
print("Interstitial ad not ready")
}
}
deinit {
interstitialAd?.destroy()
}
// MARK: - CLXInterstitialDelegate
func didLoad(_ ad: CLXAd) {
print("Interstitial ad loaded from \(ad.networkName ?? "unknown")")
retryAttempt = 0
}
func didFailToLoadAd(_ adUnitId: String, error: CLXError) {
print("Interstitial ad failed to load: \(error.localizedDescription)")
retryAttempt += 1
let delay = pow(2.0, Double(min(5, retryAttempt)))
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
self?.interstitialAd?.load()
}
}
func didDisplay(_ ad: CLXAd) {
print("Interstitial ad displayed")
}
func didFailToDisplay(_ ad: CLXAd, error: CLXError) {
print("Interstitial ad failed to display: \(error.localizedDescription)")
interstitialAd?.load()
}
func didHide(_ ad: CLXAd) {
print("Interstitial ad hidden")
interstitialAd?.load() // Reload for next use
}
func didClick(_ ad: CLXAd) {
print("Interstitial ad clicked")
}
// MARK: - CLXAdRevenueDelegate
func didPayRevenue(for ad: CLXAd) {
print("Interstitial revenue: \(ad.revenue ?? 0) from \(ad.networkName ?? "unknown")")
}
}