今天,小编要教给大家的是,如何快速在APP中集成广告功能!
首先,进入中控易动平台(www.yd-mobile.cn),创建一个应用,创建完成进入应用,然后添加AdView插件。
AdView插件:集成AdView展示广告功能,支持开屏、横幅、插屏、原生、视频等广告样式
注意:
·插件的所有接口在 deviceready 事件后生效;
使用插件需配置:SDKKEY(参考AdView插件配置);
·展示开屏、横幅、插屏、原生、视频等广告样式需要在AdView平台申请广告位(参考AdView插件配置;
·开屏广告默认展示;
·视频广告暂时只支持激励视频样式;
·当前iOS使用AdViewSDK_iOS版本是4.0.6;
·当前Android使用AdViewSDK_Android版本是4.0.9;
·广告接口调用限制30s一次;
1
展示横幅广告
navigator.adview.showBannerAd(success, error,options)
支持平台:
·Android
·iOS
参数说明
参数 | 类型 | 必填 | 说明 |
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
options | Object | 否 | 参数对象 |
success函数没有返回,直接加载广告
error函数会返回一个字符串,错误的相关信息
options参数为一个对象,其属性包含以下一项或多项:
- type(String/ 可选) --广告位置,可取值:top(顶部)、center(居中)、bottom(底部);默认值:top;(注意:以下 x、y在type基础上进行位置调整。例如:x取值30,type取值top,是在type是top的基础上向下平移30距离)
- x(Number/ 可选) -- 距离顶部的偏移量,基于type的值,默认值:0(请输入大于等于0的数),单位px
- y(Number/ 可选) -- 距离底部的偏移量,基于type的值,默认值:0(请输入大于等于0的数),单位px
·注意
- 关于type、x、y组合方式五种,选择其中一种传参:
- 1.type;
- 2.type值为top和x;
- 3.type值为center和x;
- 4.type值为center和y;
- 5.type值为bottom和y;
- 关于type在值为top时,iOS位于状态栏下方;
- 若x和y都有值且都大于0,则取x值,y值为0。
示例代码
设置广告居上显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居上显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); });}
设置广告居上向下偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居上向下偏移30显示 navigator.adview.showBannerAd( function(success) { console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'x':30,'type':'top'});}
设置广告居中显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'type':'center'});}
设置广告居中向下偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中向下偏移30显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'x':30,'type':'center'});}
设置广告居中向上偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中向上偏移30显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'y':30,'type':'center'});}
设置广告居下显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居下显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'type':'bottom'});}
设置广告居下向上偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居下向上偏移30显示 navigator.adview.showBannerAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'y':30,'type':'bottom'});}
2
展示插屏广告
navigator.adview.showInterteristalAd(success, error)
支持平台:
·Android
·iOS
参数说明
参数 | 类型 | 必填 | 说明 |
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
success函数没有返回,直接加载广告
error函数会返回一个字符串,错误的相关信息
示例代码
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ navigator.adview.showInterteristalAd(function(success) { console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); });}
3
展示原生广告
navigator.adview.showNativeAd(success, error,options)
支持平台:
·Android
·iOS
参数说明
参数 | 类型 | 必填 | 说明 |
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
options | Object | 是 | 参数对象 |
success函数没有返回,直接加载广告
error函数会返回一个字符串,错误的相关信息
options参数为一个对象,其属性包含以下一项或多项:
- positionID(String/ 必选) -- 原生广告位ID,在adview官网开发者后台申请
- type(可选) --(String/ 可选) --广告位置,可取值:top(顶部)、center(居中)、bottom(底部);默认值:top;(注意:以下 x、y在type基础上进行位置调整。例如:x取值30,type取值top,是在type是top的基础上向下平移30距离)
- x(Number/ 可选) -- 距离顶部的偏移量,基于type;默认值:0(请输入大于等于0的数),单位px
- y(Number/ 可选) -- 距离底部的偏移量,基于type;默认值:0(请输入大于等于0的数),单位px
· 注意
- 关于type、x、y组合方式五种,选择其中一种传参:
- 1.type;
- 2.type值为top和x;
- 3.type值为center和x;
- 4.type值为center和y;
- 5.type值为bottom和y;
- 关于type在值为top时,iOS位于状态栏下方;
- 若x和y都有值且都大于0,则取x值,y值为0。
示例代码
设置广告居上显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居上显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj'});}
设置广告居上向下偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居上向下偏移30显示 navigator.adview.showNativeAd( function(success) { console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','x':30,'type':'top'});}
设置广告居中显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','type':'center'});}
设置广告居中向下偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中向下偏移30显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','x':30,'type':'center'});}
设置广告居中向上偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居中向上偏移30显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','y':30,'type':'center'});}
设置广告居下显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居下显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','type':'bottom'});}
设置广告居下向上偏移30显示
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ //设置广告居下向上偏移30显示 navigator.adview.showNativeAd( function (success){ console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSIDs38o5ybf6agj','y':30,'type':'bottom'});}
4
展示视频广告
navigator.adview.showVideoAd(success, error,options)
支持平台:
·Android
·iOS
参数说明
参数 | 类型 | 必填 | 说明 |
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
options | Object | 是 | 参数对象 |
success函数没有返回,直接加载广告
error函数会返回一个字符串,错误的相关信息
options参数为一个对象,其属性包含以下一项或多项:
- positionID(String/ 必选) -- 视频广告位ID,在adview官网开发者后台申请
示例代码
// 监听’deviceready‘事件document.addEventListener('deviceready', onDeviceReady, false)function onDeviceReady(){ navigator.adview.showVideoAd(function (success) { console.log(JSON.stringify(success)); },function (error){ alert(JSON.stringify(error)); },{'positionID':'POSID74pjtjpxo516'});}
以上就是使用AdView插件的全部教程了,快去试试吧!
版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除