Skip to content

互动广告

启动广告

首先创建互动广告实例对象 CTInteractiveAd ,然后调用其 openAd 方法

objc
#import <CartySDK/CartySDK.h>

self.interactiveAd = [[CTInteractiveAd alloc] init];
self.interactiveAd.placementid = @"<your-placement-id>";
self.interactiveAd.delegate = self;
[self.interactiveAd openAd:rootViewController];
swift
import CartySDK

interactiveAd = CTInteractiveAd()
interactiveAd.placementid = "<your-placement-id>"
interactiveAd.delegate = self
interactiveAd.open(rootViewController)

实现监听回调

实现 CTInteractiveAdDelegate 接收广告相关回调通知

objc
- (void)CTInteractiveAdDidOpen:(nonnull CTInteractiveAd *)ad
{
    NSLog(@"启动成功");
}

- (void)CTInteractiveAdOpenFail:(nonnull CTInteractiveAd *)ad withError:(nonnull NSError *)error
{
    NSLog(@"启动失败: %@",error.localizedDescription);
}

- (void)CTInteractiveAdDidDismiss:(nonnull CTInteractiveAd *)ad
{
    NSLog(@"广告已关闭");
}
swift

func ctInteractiveAdDidOpen(_ ad: CTInteractiveAd) {
    print("启动成功")
}
    
func ctInteractiveAdOpenFail(_ ad: CTInteractiveAd, withError error: any Error) {
    print("启动失败 \(error.localizedDescription)")
}
    
func ctInteractiveAdDidDismiss(_ ad: CTInteractiveAd) {
    print("广告已关闭")
}