更新记录
2.2.5(2023-11-30)
- iOS sdk更新至10.13.0,安卓sdk更新至22.5.0
- 这版本iOS没有加入模拟器架构,不支持模拟器运行
- 安卓compile提升到最新,谷歌应用市场没得问题
2.2.4(2023-05-05)
安卓SDK更新至'com.google.android.gms:play-services-ads:22.0.0' iOSSDK更新至10.4.0 修复一些已知问题
2.2.3(2022-10-17)
修复安卓某些机型存在的bug
查看更多平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 14.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:支持 | 适用版本区间:11 - 17 |
更新内容
- iOS sdk更新至10.13.0,安卓sdk更新至22.5.0
- 这版本iOS没有加入模拟器架构,不支持模拟器运行
- 开屏广告不再需要屏幕方向参数
- 详见demo
联系作者
作者qq,添加请备注来意,否则不会同意添加。
请先下载demo代码试用成功后购买,有问题请先认真阅读文档或者查看demo代码,测试appid请使用:ca-app-pub-3940256099942544~1458002511
插件集成
所有类型的广告都建议提前加载,然后在需要的时候显示。插屏广告和激励广告在上一个广告消失之后会自动预加载一个广告。banner广告推荐在加载成功回调之后再显示。
广告创建或者显示方法都带有callback,callback回来的数据是一个object,结构为{"eventType":"", "msg":""},具体的eventType根据不同广告而定,见具体广告下的说明,banner广告的所有事件也请看banner下面的文档说明
banner广告
注意:banner广告只能在nvue中使用
<HXR-GoogleMobileADBannerAd style="width:750rpx;height:50px;background-color: #555555;" adUnitID="ca-app-pub-3940256099942544/2934735716" @adLoaded="myload()" @adFail="myfail()"></HXR-GoogleMobileADBannerAd>
methods: {
myload:function(e){
uni.showToast({
title:'加载完成'
})
},
myfail:function(e){
uni.showToast({
title:'加载失败'
})
}
}
banner广告所有事件
- adFail
- adLoaded
- adWillPresentScreen
- adWillDismissScreen
- adDidDismissScreen
banner广告尺寸设置,
不设置默认是50px高度,支持的尺寸有如下几种
- kGADAdSizeBanner 50px
- kGADAdSizeLargeBanner 100px
- kGADAdSizeMediumRectangle 300x250px
- kAutoHeightWithWidth 根据宽度自适应高度,高度在50-90px
不建议将尺寸自由设置,应尽量使用上面提供的尺寸
插屏广告
<button type="default" @click="showInterstitialAd()">插屏广告</button>
var googleInterstitialAd = uni.requireNativePlugin('HXR-GoogleMobileADInterstitialAd');
onLoad() {
googleInterstitialAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4411468910', function(res){
console.log(JSON.stringify(res));
});
}
showInterstitialAd:function(){
googleInterstitialAd.showWithCallback(function(res){
console.log(JSON.stringify(res));
});
},
插屏广告的所有事件
- adLoaded
- adFail
- adWillPresentScreen
- adWillDismissScreen
- adDidDismissScreen
- adFailToPresent
- adNotReady
- didClick
激励广告
<button type="default" @click="showRewardedAd()">激励广告</button>
var googleRewardedAd = uni.requireNativePlugin('HXR-GoogleMobileADRewardedAd');
onLoad() {
////不传入验证参数
// googleRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/1712485313', function(res){
// console.log(JSON.stringify(res));
// });
googleRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/1712485313', function(res){
console.log(JSON.stringify(res));
}, {'userIdentifier':'your user identifier', 'customRewardString': 'your customRewardString'});
},
showRewardedAd:function(){
googleRewardedAd.showWithCallback(function(res){
console.log(JSON.stringify(res));
});
}
激励广告的所有事件
- adFail
- adLoaded
- adNotReady
- userDidEarnReward
- adWillPresentScreen
- adWillDismissScreen
- adFailToPresent
- adDidDismissScreen
- didClick
插屏激励广告
<button type="default" @click="showInterstitialRewardedAd()">插屏激励广告</button>
var googleInterstitialRewardedAd = uni.requireNativePlugin('HXR-GoogleMobileADRewardedInterstitialAd');
onLoad() {
////不传入验证参数
// googleInterstitialRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4806952744', function(res){
// console.log(JSON.stringify(res));
// });
googleInterstitialRewardedAd.createADWithAdUnitID('ca-app-pub-3940256099942544/4806952744', function(res){
console.log(JSON.stringify(res));
}, {'userIdentifier':'your user identifier', 'customRewardString': 'your customRewardString'});
}
showInterstitialRewardedAd:function(){
googleInterstitialRewardedAd.showWithCallback(function(res){
console.log(JSON.stringify(res));
});
}
插屏激励广告的所有事件
- adFail
- adLoaded
- adNotReady
- userDidEarnReward
- adWillPresentScreen
- adWillDismissScreen
- adFailToPresent
- adDidDismissScreen
- didClick
开屏广告
开屏广告是在APP前后台切换时动作,故只能在APP.vue中使用, 开屏广告除了需要广告id参数外,还需要一个屏幕方向参数,如果不传方向参数,则默认竖屏,方向参数列举如下:
1 = UIDeviceOrientationPortrait, 竖屏2 = UIDeviceOrientationPortraitUpsideDown, 竖屏,home键在上3 = UIDeviceOrientationLandscapeRight, 横屏,home键在右- ~~4 = UIDeviceOrientationLandscapeLeft, 横屏,home键在左 归结为不传或者传1或者2为竖屏,传3或者4为横屏~~
开屏广告所有事件
- adFail
- adLoaded
- adNotReady
- userDidEarnReward
- adWillPresentScreen
- adWillDismissScreen
- adFailToPresent
- adDidDismissScreen
- didClick
<script>
var googleAppOpenAd = uni.requireNativePlugin('HXR-GoogleMobileADAppOpenAd');
export default {
onLaunch: function() {
console.log('App Launch');
///orientation 默认不传则为竖屏竖屏
/// 1 = UIDeviceOrientationPortrait, 竖屏
/// 2 = UIDeviceOrientationPortraitUpsideDown, 竖屏,home键在上
/// 3 = UIDeviceOrientationLandscapeRight, 横屏,home键在右
/// 4 = UIDeviceOrientationLandscapeLeft, 横屏,home键在左
googleAppOpenAd.createADWithAdUnitID({'adUnitID':'ca-app-pub-3940256099942544/5662855259','orientation':1}, res => {
console.log(JSON.stringify(res));
uni.showToast({
title: res.msg
});
});
},
onShow: function() {
console.log('App Show');
uni.showToast({
title:'App Show'
})
googleAppOpenAd.showWithCallback(function(res) {
console.log(JSON.stringify(res));
uni.showToast({
title: res.msg
});
});
},
onHide: function() {
console.log('App Hide');
}
};
</script>
<style>
/*每个页面公共css */
</style>
manifest.json配置
原生插件栏,填写你的GADApplicationIdentifier即可
安卓打包集成
安卓云打包请使用hbuilder 2.8.11及以上版本打包