has.createInterstitialAd(Object object): InterstitialAd
创建插屏广告实例。每次调用该方法创建都会返回一个全新的实例,插屏广告实例不允许跨页面使用。
起始版本: 2.0.2
约束与限制:
当前接口在元服务被嵌入式运行时暂不支持使用,建议规避或替换类似功能接口。
参数:
参数为Object对象,包括以下字段。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| adUnitId | string | 是 | 广告单元id。 如果仅调测广告,可使用测试广告位ID:testb4znbuh3n2; 如果要接入正式广告,则需要申请正式的广告位ID。可在应用发布前进入流量变现官网,点击“开始变现”,登录鲸鸿动能媒体服务平台进行申请,具体操作详情请参见展示位创建。 |
返回值:
返回InterstitialAd实例对象。
错误码:
| 错误码 | 错误信息 |
|---|---|
| 17000901 | adId already exists. |
示例:
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
}); InterstitialAd.load(): Promise<void>
加载插屏广告。
起始版本: 2.0.2
错误码:
| 错误码 | 错误信息 |
|---|---|
| 17000201 | 1. Interstitial load params invalid. 2. Interstitial ad load failed. |
| 17000601 | 1. can't invoke load() while is showed. 2. loadAd error. |
示例:
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.load().then(() => {
console.info('InterstitialAd load success');
}).catch((err) => {
console.error('InterstitialAd load fail', err);
}); InterstitialAd.show(): Promise<void>
显示插屏广告。需要先调用InterstitialAd.load加载插屏广告。
起始版本: 2.0.2
错误码:
| 错误码 | 错误信息 |
|---|---|
| 17000501 | 1. Interstitial show params invalid. 2. Interstitial ad show failed. |
| 17000701 | 1. 当前正在播放激励视频广告或者插屏广告,不允许再次展示. 2. 距离广告上次播放时间间隔不足,不允许展示. 3. showAd error. |
示例:
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onLoad(() => {
console.info('InterstitialAd onLoad callback triggered');
interstitialAd.show().then(() => {
console.info('InterstitialAd show success');
}).catch((err) => {
console.error('InterstitialAd show fail', err);
});
interstitialAd.offLoad();
});
interstitialAd.load(); InterstitialAd.destroy()
销毁插屏广告实例。
起始版本: 2.0.2
错误码:
| 错误码 | 错误信息 |
|---|---|
| 102 | destroy -> Interstitial destroy params invalid. |
示例:
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.destroy(); InterstitialAd.onLoad(function callback)
监听插屏广告加载事件。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 是 | 插屏广告加载事件的监听函数。 |
示例:
const interstitialAdOnLoadFn = function() {
console.info('InterstitialAd onLoad callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onLoad(interstitialAdOnLoadFn); InterstitialAd.offLoad(function callback)
移除插屏广告加载事件的监听函数。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 否 | InterstitialAd.onLoad传入的监听函数,不传此参数则移除所有监听函数。 |
示例:
const interstitialAdOnLoadFn = function() {
console.info('InterstitialAd onLoad callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onLoad(interstitialAdOnLoadFn);
interstitialAd.offLoad(interstitialAdOnLoadFn);
interstitialAd.offLoad(); InterstitialAd.onError(function callback)
监听插屏广告错误事件。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 是 | 插屏广告错误事件的监听函数。 |
示例:
const interstitialAdOnErrorFn = function() {
console.error('InterstitialAd onError callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onError(interstitialAdOnErrorFn); InterstitialAd.offError(function callback)
移除插屏广告错误事件的监听函数。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 否 | InterstitialAd.onError传入的监听函数,不传此参数则移除所有监听函数。 |
示例:
const interstitialAdOnErrorFn = function() {
console.error('InterstitialAd onError callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onError(interstitialAdOnErrorFn);
interstitialAd.offError(interstitialAdOnErrorFn);
interstitialAd.offError(); InterstitialAd.onClose(function callback)
监听插屏广告关闭事件。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 是 | 插屏广告关闭事件的监听函数。 |
示例:
const interstitialAdOnCloseFn = function() {
console.info('InterstitialAd onClose callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onClose(interstitialAdOnCloseFn); InterstitialAd.offClose(function callback)
移除插屏广告关闭事件的监听函数。
起始版本: 2.0.2
参数:
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| callback | function | 否 | InterstitialAd.onClose传入的监听函数,不传此参数则移除所有监听函数。 |
示例:
const interstitialAdOnCloseFn = function() {
console.info('InterstitialAd onClose callback triggered');
};
const interstitialAd = has.createInterstitialAd({
adUnitId: 'testb4znbuh3n2' // 此处的adUnitId仅供测试,请开发者更换为正式的广告id。
});
interstitialAd.onClose(interstitialAdOnCloseFn);
interstitialAd.offClose(interstitialAdOnCloseFn);
interstitialAd.offClose();