启动页广告又称开屏广告。启动页(也称为闪屏/开屏 Splash)是在应用启动之后,系统 LaunchScreen
结束时展示,应用首页出现时消失。
在客户端配置启动页后,您可以在控制台侧配置 Splash 展位信息与广告内容(参见 创建展位 和 创建营销活动),应用根据配置获取展位投放数据并进行展示,实现了投放数据的动态下发与展示。
基于 mPaaS 框架(关于 mPaaS 框架的详细介绍,参见 mPaaS 框架介绍)下,启动页的时序和原理如下:
Launcher
微应用展示完成时,将关闭启动页,此时再切换回主 window。确保已正确启动智能投放组件,操作参见 启动组件。
在 mPaaS 框架自动生成的框架分类文件 DTFrameworkInterface+MPCDPDemo_plugin.m
中(如下图所示),完成以下配置:
window
对象。
static UIWindow *splashScreenWindow;
在框架分类文件的 application:handleDidFinishLaunchingWithOptions:
方法中,实现启动页广告的逻辑并打开启动页。
- (DTFrameworkCallbackResult)application:(UIApplication *)application handleDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 广告逻辑
// 查看启动页是否存在
BOOL showSplashWindow = YES;
showSplashWindow = splashScreenExist(showSplashWindow);
if (showSplashWindow) {
__weak typeof(self) weakSelf = self;
// 打开启动页
splashScreenWindow = APSplashScreenStart(^{
// 启动页关闭的回调
[weakSelf splashScreenDidDismiss];
});
}
return DTFrameworkCallbackResultContinue;
}
实现启动页关闭的逻辑。
包括切换应用主 window,释放启动页 window 以及发送启动页结束的通知(可选)。
- (void)splashScreenDidDismiss {
// 将应用主 window 还原为 key window
[DTContextGet().window makeKeyAndVisible];
[self performSelector:@selector(doDismiss) withObject:nil afterDelay:0.0];
}
- (void)doDismiss {
// 释放启动页对象
splashScreenWindow.rootViewController = nil;
splashScreenWindow = nil;
[self notifySplashScreenDismiss];
}
- (void)notifySplashScreenDismiss {
// 闪屏结束通知,处理其它逻辑(可选)
[[NSNotificationCenter defaultCenter] postNotificationName:@"kSplashScreenDidDismiss" object:nil];
}
application:afterDidFinishLaunchingWithOptions:
方法中调用。
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
APWillKillSplashScreen();
// ...
}
在首页 ViewController 启动后发送通知,真正关闭启动页。
ViewController 通常为 Launcher 微应用的 rootViewController,如果是 TabBarController,则为第一个 tab 所在的 ViewController。
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// 通知 Launcher 已经展示
[[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationLauncherDidAppear" object:nil];
}
@end
启动页相关接口说明参见 API 说明。
在文档使用中是否遇到以下问题
更多建议
匿名提交