LDAdServiceMoPub 1.0.0

LDAdServiceMoPub 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可 自定义
发布上次发布2015年2月

Imanol Fernandez 维护。



 
依赖项
LDAdService>= 0
mopub-ios-sdk>= 0
 

  • Imanol Fernandez

针对广告的 Atomic 插件

此仓库包含使用 Atomic Plugins 范式设计的广告 API。让您的应用盈利,并利用所有提供的功能:优雅的 API、灵活的跨平台货币化解决方案、全面支持横幅和全屏广告(插屏广告)、针对不同广告商的单个 API 等。该 API 目前已在许多语言中可用,我们计划未来添加更多。

目前实现了 2 种广告提供者,但可以轻松添加更多。

  • MoPub(可选适配器)
  • AdMob

您可以帮助创建更多出色的插件。

关于 Atomic Plugins

Atomic Plugins 提供一个优雅且极简的 API,从一开始就考虑到便携性。通过设计避免框架依赖项,因此插件可以在任何平台上运行,可以与任何应用程序框架或游戏引擎集成。

提供的 API

iOS API

API 参考

请在 API 文档 中查看

请查看 LDAdService.hLDAdBanner.hLDAdInterstitial.h 头文件以了解 API 的完整功能

请查看 AdTest 中的完整项目,测试 API 提供的所有功能。

简介

LDAdService 类提供了一个易于使用的广告 API,可以与不同广告提供商一起使用,并内置了对多个横幅和插页式广告的支持。

设置您的项目

您可以使用 CocoaPods 包含所需广告提供商

pod 'LDAdServiceMoPub' //for MoPub
pod 'LDAdServiceAdMob' //for AdMob

如果您使用 MoPub,还可选择包含以下适配器

Charboost 适配器 AdMob 适配器 Millennial Media 适配器

示例

//Instantiathe the desired ad provider
LDAdService * service = [[LDAdServiceMoPub alloc] init]; //MoPub
LDAdService * service = [[LDAdServiceAdMob alloc] init]; //AdMob

//Configure default banner and interstitial adunits
service.settings.banner = @"....";
service.settings.bannerIpad = @"...."; //optional (use if you want an specific AdUnit for iPad)
service.settings.interstitial = @"....";
service.settings.interstitialIpad = @"...."; //optional (use if you want an specific AdUnit for iPad)

//Create banner: optional AdUnit and AdSize arguments
LDAdBanner * banner = [service createBanner];
banner.delegate = self; //optional banner delegate
[banner loadAd];

//Layout the view as you want
[self.view addSubview: banner.view]; 
banner.view.center = self.view.center;

//Create interstitial: optional AdUnit argument
LDAdInterstitial * interstitial  = [service createInterstitial];
interstitial.delegate = self; //optional delegate
[interstitial loadAd];

//Show an interstitial
[interstitial showFromViewController:self animated:YES];

Android API

API 参考

请参阅 API 文档

请参阅 AdTest 以测试 API 中提供的所有功能。

介绍

AdService 接口提供了一个易于使用的广告 API,可以与不同广告提供商一起使用,并内置了对多个横幅和插页式广告的支持。

设置您的项目

发布版本已部署到 Maven Central。您只需在 build.gradle 中添加所需的依赖项。

dependencies {
    compile 'com.ludei.ads.admob:1.0.0' //AdMob Ad Provider

    compile 'com.ludei.ads.mopub:1.0.0' //MoPub Ad Provider
    compile 'com.ludei.ads.mopub.adcolony:1.0.0' //Optional MoPub AdColony adapter
    compile 'com.ludei.ads.mopub.admob:1.0.0' //Optional MoPub AdMob adapter
    compile 'com.ludei.ads.mopub.charboost:1.0.0' //Optional MoPub Charboost adapter
    compile 'com.ludei.ads.mopub.inmobi:1.0.0' //Optional MoPub InMobi adapter
    compile 'com.ludei.ads.mopub.greystripe:1.0.0' //Optional MoPub Greystriper adapter
    compile 'com.ludei.ads.mopub.millennialmedia:1.0.0' //Optional MoPub MillennialMedia adapter
}

示例

//Instantiathe the desired ad provider
AdService service = new AdServiceMoPub(); //MoPub
AdService service = new AdServiceAdMob(); //AdMob

//Configure default banner and interstitial adunits
service.configure(bannerAdUnit, interstitialAdUnit);

//Create banner: optional AdUnit and AdSize arguments
AdBanner banner = service.createBanner(this);
banner.setListener(this); //Optional banner listener
banner.loadAd();

//Layout the banner as you want
viewGroup.addView(banner.getView());

//Create interstitial: optional AdUnit argument
AdInterstitial interstitial = service.createInterstitial(this);
interstitial.setListener(this); //Optional interstitial listener
interstitial.loadAd();

//Show an interstitial
interstitial.show();

JavaScript API

API 参考

请参阅 API 文档

若要测试 API 中提供的所有功能,请运行以下命令

gulp create-cordova

介绍

Cocoon.Ad 类提供了一个易于使用的广告 API,可以与不同广告提供商一起使用,并内置了对多个横幅和插页式广告的支持。

设置您的项目

发布版本已部署到 Cordova 插件注册中心。您只需使用 Cordova CLI、CocoonJS CLI 或 Ludei 的 Cocoon Cloud 服务器安装所需的插件。

cordova plugin add com.ludei.ads.ios.admob; //AdMob plugin for iOS
cordova plugin add com.ludei.ads.ios.mopub; //MoPub plugin for iOS
cordova plugin add com.ludei.ads.android.admob; //AdMob plugin for Android
cordova plugin add com.ludei.ads.android.mopub; //MoPub plugin for Android

//Optional MoPub adapters for iOS and Android
cordova plugin add com.ludei.ads.ios.mopub.charboost;
cordova plugin add com.ludei.ads.ios.mopub.admob;
cordova plugin add com.ludei.ads.ios.mopub.millennial;
cordova plugin add con.ludei.ads.android.adcolony;
cordova plugin add con.ludei.ads.android.admob;
cordova plugin add con.ludei.ads.android.charboost;
cordova plugin add con.ludei.ads.android.greystripe;
cordova plugin add con.ludei.ads.android.inmobi;
cordova plugin add con.ludei.ads.android.millennial;

请将以下 JavaScript 文件包含在您的 html 项目中

cocoon.js cocoon_ads.js

示例

//get the installed plugin instance
var service = Cocoon.Ad;

//multiplatform default configuration
service.configure({
    ios: {
         banner:"agltb3B1Yi1pbmNyDQsSBFNpdGUxxxxxxx",
         bannerIpad:"agltb3B1Yi1pbmNyDQsSBFNpdGUzzzzz", //optional
         interstitial:"agltb3B1Yi1pbmNyDQsSBFNpdGUyyyyyyy",
         interstitialIpad:"agltb3B1Yi1pbmNyDQsSBFNpdGUtttttt", //optional
    },
    android: {
         banner:"agltb3B1Yi1pbmNyDQsSBFNpdGUwwwwww",
         interstitial:"agltb3B1Yi1pbmNyDQsSBFNpdGUhhhhhh"
    }
);

//Create banner: optional AdUnit and BannerSize arguments
var banner = service.createBanner();

//Configure banner listeners
banner.on("load", function(){
   console.log("Banner loaded " + banner.width, banner.height);
   banner.show();
});

banner.on("fail", function(){
   console.log("Banner failed to load");
});

banner.on("show", function(){
   console.log("Banner shown a modal content");
});

banner.on("dismiss", function(){
   console.log("Banner dismissed the modal content");
});

banner.on("click", function(){
   console.log("Banner clicked");
});

 //load banner
banner.load();

//Show or hide banner
banner.show();
banner.hide();

//Automatic banner layout
banner.setLayout(Cocoon.Ad.BannerLayout.TOP_CENTER);

//Custom banner layout
banner.setLayout(Cocoon.Ad.BannerLayout.CUSTOM);
banner.setPosition(x,y);

//Create interstitial: optional AdUnit argument
interstitial = service.createInterstitial();

//Configure interstitial listeners
interstitial.on("load", function(){
    console.log("Interstitial loaded");
});
interstitial.on("fail", function(){
    console.log("Interstitial failed");
});
interstitial.on("show", function(){
    console.log("Interstitial shown");
});
interstitial.on("dismiss", function(){
    console.log("Interstitial dismissed");
});

interstitial.on("click", function(){
    console.log("Interstitial clicked");
});

//load interstitial
interstitial.load();

//show interstitial
interstitial.show();

C++ API

API 参考

请参阅 API 文档

请参阅 AdService.hAdBanner.hAdInterstitial.h 头文件,以便全面了解 API 的功能。

请参阅 AdTest 以测试集成 C++ 广告 API 的完整项目(cocos2dx 游戏)。

介绍

AdService类提供了一个易于使用的广告API,可以与不同的广告提供者一起使用,并内置了对多个横幅和插屏的支持。

设置你的项目

您可以从版本页面下载预构建的头文件和静态库。

这些静态库提供了C++和本地平台(iOS、Android、WP等)之间的绑定。您可能需要在项目中添加一些依赖平台库(例如一些jar文件或gradle依赖项)。请参阅AdTest了解已设置的多平台C++项目的示例。

为Android所需的特定设置

在Android上,没有便携和可靠的方式获取当前的Activity和生命周期事件,我们不希望依赖于特定的游戏引擎工具API。C++和Java的桥梁是通过SafeJNI实用工具实现的。Atomic Plugins利用这个类,并将其用作通用的Activity和生命周期事件通知提供者。请参阅以下代码以设置atomic plugins的活动以及通知Android生命周期事件。

@Override
public void onCreate(Bundle savedInstanceState) {
    //set the activity for atomic plugins and load safejni.so
    SafeJNI.INSTANCE.setActivity(this); 
    super.onCreate(savedInstanceState);
}

可选的(但推荐)您可以使用setJavaToNativeDispatcher来配置异步回调应该调度的线程。默认情况下,回调在UI线程中调度。例如,以下调度器用于Cocos2dx游戏引擎测试项目。

@Override
public Cocos2dxGLSurfaceView onCreateView() {
    final Cocos2dxGLSurfaceView surfaceView = super.onCreateView();
    SafeJNI.INSTANCE.setJavaToNativeDispatcher(new SafeJNI.JavaToNativeDispatcher() {
        @Override
        public void dispatch(Runnable runnable) {
            surfaceView.queueEvent(runnable);
        }
    });
    return surfaceView;
}

示例

//Easy to use static method to instantiate a new service
//You can pass a specific AdProvider if you have many providers linked in your app and you want to choose one of them at runtime
AdService * service = AdService::create();

//Configure default banner and interstitial adunits
AdServiceSettings settings;
settings.banner = "ca-app-pub-7686972479101507/xxxxxxxx";
settings.interstitial = "ca-app-pub-7686972479101507/xxxxxx";
service->configure(settings);

//Create banner: optional AdUnit and AdSize arguments
AdBanner * banner = service->createBanner();
banner->setListener(this); //Optional banner listener
banner->loadAd();

//Automatic layout
banner->setLayout(AdBannerLayout::TOP_CENTER);

//Custom layout
banner->setLayout(AdBannerLayout::CUSTOM);
banner->setPosition(x, y);

//Create interstitial: optional AdUnit argument
AdInterstitial * interstitial = service->createInterstitial();
interstitial->setListener(this); //Optional interstitial listener
interstitial->loadAd();

//Show an interstitial
interstitial->show();

//delete the ads or the service when you are done. You can wrap them into a Smart Pointer if you want.
delete banner;
delete interstitial;
delete service; 

许可

Mozilla公共许可证,版本2.0

版权所有(c)2015 Ludei

请参阅MPL 2.0 许可证