前言
在将广告单元集成到您的应用之前,您必须:
- 在 OpenMediation用户界面中,创建一个应用并创建一个广告展示位置,您可以在此处按照指南进行操作 。
- 将OpenMediation SDK集成到您的项目中, 按照我们的操作步骤进行iOS SDK集成 。
- 如果您使用聚合,请转到集成广告网络,并确保已添加广告网络的SDK以及希望在应用中使用的相应适配器。
开屏广告
步骤 1. 初始化开屏广告
OpenMediation SDK触发几个事件来通知您开屏广告活动。要显示开屏广告,需要创建一个全新的OMSplash对象,设置它的委托并加载广告。
创建OMSplash对象
下面的代码片段演示了如何使用OMSplash类来创建Splash对象,并实现OMSplashDelegate接口来接收Splash广告事件。SDK将通知委托所有可能发生的事件如下:
@property (nonatomic, strong) OMSplash *splash;
- (void)viewDidLoad {
self.splash = [[OMSplash alloc] initWithPlacementId:@"YOUR_PLACEMENT_ID" adSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
self.splash.delegate = self;
}
private lazy var splash: OMSplash = {
let splash = OMSplash(placementID: "YOUR_PLACEMENT_ID" adSize: self.view.frame.size)
splash.delegate = self
return splash
}()
Splash Delegate (OMSplashDelegate)
在代码中实现以下回调函数,以在收到广告活动时处理广告逻辑。 例如 ,在准备好开屏广告后, 调用show 函数将广告投放给您的用户。
通过 OMSplashDelegate 协议 声明的方法, 允许采用的委托响应来自 OMSplash 类的 消息 ,从而响应诸如是否已加载本机广告之类的操作。
/// Invoked when the splash ad is available.
- (void)omSplashDidLoad:(OMSplash *)splash {
NSLog(@"SplashAd Did Load");
}
/// Invoked when the call to load a splash has failed.
/// Parameter error contains the reason for the failure.
- (void)omSplashFailToLoad:(OMSplash *)splash withError:(NSError *)error {
NSLog(@"SplashAd Did Fail");
}
/// Invoked when the splash ad is showing.
- (void)omSplashDidShow:(OMSplash *)splash {
NSLog(@"SplashAd Did Show");
}
/// Invoked when the user clicks on the splash ad.
- (void)omSplashDidClick:(OMSplash *)splash {
NSLog(@"SplashAd Did Click");
}
/// Invoked when the splash ad has been closed.
- (void)omSplashDidClose:(OMSplash *)splash {
NSLog(@"SplashAd Did Close");
}
/// Invoked when the splash ad did Show Fail.
- (void)omSplashDidFailToShow:(OMSplash *)splash withError:(NSError *)error {
NSLog(@"SplashAd Did Show Fail");
}
/// Invoked when the splash ad is available.
func omSplashDidLoad:(_ splash: OMSplash) {
print("SplashAd Did Load")
}
/// Invoked when the call to load a splash has failed.
/// Parameter error contains the reason for the failure.
func omSplashDidFail:(toLoad splash: OMSplash, withError error: Error) {
print("SplashAd Did Fail")
}
/// Invoked when the splash ad is shown.
func omSplashDidShow:(_ splash: OMSplash) {
print(@"SplashAd Did Show")
}
/// Invoked when the splash ad is shown fail.
func omSplashDidFail:(toShow splash: OMSplash, withError error: Error) {
print(@"SplashAd Did Show fail")
}
/// Invoked when the user clicks on the splash ad.
func omSplashDidClick(_ splash: OMSplash) {
print("SplashAd Did Click")
}
/// Invoked when the splash ad has been closed.
func omSplashDidClose(_ splash: OMSplash) {
print(@"SplashAd Did Close")
}
Step 2. Load and Show a Banner Ad
调用以下方法向用户请求开屏广告:
Step 3. Show a Splash Ad
调用以下方法向用户投放原生广告:
[self.splash showWithWindow:[UIApplication sharedApplication].keyWindow customView:nil];
self.splash.show(with:"WINDOW" customView:"CUSTOM_VIEW")
评论
文章评论已关闭。