更新记录

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

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


更新内容

  • iOS sdk更新至10.13.0,安卓sdk更新至22.5.0
  • 这版本iOS没有加入模拟器架构,不支持模拟器运行
  • 开屏广告不再需要屏幕方向参数
  • 详见demo

联系作者

作者qq:724300087,添加请备注来意,否则不会同意添加。

请先下载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及以上版本打包

详细使用详见demo

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据 谷歌三方SDK下载地址:https://developers.google.com/admob/ios/download?hl=zh-CN 谷歌三方SDK是否采集数据,请参考:https://developers.google.com/admob/ios/quick-start?hl=zh-CN

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问