这个存储库包含了采用原子插件范式设计广告API。利用您的应用并充分利用提供的所有功能:优雅的API、灵活的跨多个平台实现的货币化解决方案、完全支持横幅广告和全屏广告(插屏广告)、针对不同广告提供商的单个API等。该API已在多种语言中可用,我们计划在未来添加更多。
目前实现了2个广告提供商,但可以轻松添加新的。
您可以通过贡献来帮助创建更多精彩的插件。
原子插件提供优雅且简约的API,并且从一开始就考虑了便携性。通过设计避免了框架依赖,因此插件可以运行在任何平台上,并且可以与任何应用框架或游戏引擎集成。
查看API文档
查看LDAdService.h
LDAdBanner.h
LDAdInterstitial.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];
请参阅 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();
请参阅 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;
在您的 html 项目中包含以下 JavaScript 文件
//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();
请参阅 API 文档
请参阅 AdService.h
AdBanner.h
AdInterstitial.h
头文件,以获取 API 功能的完整概述。
请参阅 AdTest
以了解集成了 C++ 广告 API 的完整项目(cocos2dx 游戏)。
AdService 类提供了一个易于使用的广告 API,可以使用不同广告提供商,并且内置了对多个横幅和插页的支持。
您可以从 发布页面 下载预构建的头文件和静态库。
这些静态库提供了 C++ 和原生平台(iOS、Android、WP 等)之间的绑定。您可能需要在项目中添加一些平台相关的库(例如,一些 jar 文件或 gradle 依赖项)。请参阅 AdTest
以了解已设置的 C++ 多平台项目。
在 Android 中,目前没有一种便携且可靠的获取当前 Activity 和生命周期事件的方法,我们不希望依赖特定游戏引擎工具 API。使用 SafeJNI 工具实现 C++ 和 Java 的桥接。Atomic Plugins 通过利用这个类,还将其用作通用 Activity 和生命周期事件通知提供者。请参见以下代码以设置 atomic 插件的 Activity,并通知 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 Public License,版本 2.0
版权所有(c)2015 Ludei
请参阅 MPL 2.0 License