在网络异常、首次冷启动等场景下,可能存在线上配置拉取失败的情况,导致无广告返回,为减少这种情况带来的流量浪费,GroMore提供两种解决方案:① 针对所有样式的本地导入配置;② 针对开屏样式的自定义兜底
Android
String configJsonStr = "在平台下载的配置文件字符串";
JSONObject configJsonObj = null;
try {
configJsonObj = new JSONObject(configJsonStr);
} catch (JSONException e) {
}
TTAdConfig.Builder adConfig = new TTAdConfig.Builder()
.appId("应用Id")
.setMediationConfig(
new MediationConfig.Builder()
.setCustomLocalConfig(configJsonObj)
.build()
)
.build()
TTAdSdk.init(context, adConfig, new TTAdSdk.InitCallback() {});
iOS
xxxxxxxxxx
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BUAdSDKConfiguration *configuration = [BUAdSDKConfiguration configuration];
configuration.appID = "XXXXXX"; //应用ID
configuration.useMediation = YES;//开启聚合功能
configuration.mediation.advanceSDKConfigPath = [[NSBundle mainBundle]pathForResource:"GroMore-config-ios-5000546" ofType:"json"];//导入本地配置文件
return YES;
}
Android
xxxxxxxxxx
//第一步、创建开屏自定义兜底对象
MediationSplashRequestInfo csjSplashRequestInfo = new MediationSplashRequestInfo(
MediationConstant.ADN_PANGLE, // 穿山甲
"代码位Id", // adn开屏广告代码位Id,注意不是聚合广告位Id
"appId", // adn应用id,注意要跟初始化传入的保持一致
"appKey" // adn没有appKey时,传入空即可
) {};
//第二步、创建AdSlot
AdSlot adSlot = new AdSlot.Builder()
.setCodeId(getResources().getString(R.string.splash_media_id))
.setImageAcceptedSize(widthPx, heightPx)
.setMediationAdSlot(
new MediationAdSlot.Builder()
//将自定义兜底对象设置给AdSlot
.setMediationSplashRequestInfo(csjSplashRequestInfo)
.build())
.build();
// 第三步,请求广告
TTAdNative adNativeLoader = TTAdSdk.getAdManager().createAdNative(this);
adNativeLoader.loadSplashAd(adSlot, mCSJSplashAdListener, 3500);
iOS
xxxxxxxxxx
BUAdSlot *slot = [[BUAdSlot alloc]init];
slot.ID = self.viewModel.slotID;// 代码位ID 仅聚合支持该功能
BUMSplashUserData *splashUserData = [[BUMSplashUserData alloc]init];
splashUserData.adnName = "baidu";// adn的名字,请使用如下值 'pangle','baidu','gdt','ks','mtg','sigmob'其他值可能导致无法加载广告
splashUserData.rit = "xxxxxxxx";// adn对应代码位
splashUserData.appID = "xxxxxxxx";// adn对应appID
splashUserData.appKey = "xxxxxxxx";// adn对应appKey, 没有时可不传
slot.mediation.splashUserData = splashUserData;