libgdx robovm admob IOS SDK的綁定,libgdxrobovm
IOS裡面主要的廣告平台就是用的是ADMOB, 在最新的ADMOB採用的是framework的方式,在繫結項目https://github.com/BlueRiverInteractive/robovm-ios-bindings/tree/master/admob已經不能正常使用了. 看到大家都有需求, 加班到淩晨1點鐘,總算把它搞定了. 遇到了有些問題始終解決不了. 下面來介紹下怎麼使用.
1.遇到的困難,
因為admob中有幾處奇葩的寫法,導致無法使用隱藏的symbol. 解決方案是自訂了一個.a然後寫綁定 搞定
2.使用方法
在core項目中定義介面
public interface ITools {public void showInterAd();public void showBanner();}
然後在Game裡面傳入它
public class GdxGame extends ApplicationAdapter {SpriteBatch batch;Texture img;ITools tools;public GdxGame(ITools tools) {this.tools = tools;}@Overridepublic void create () {batch = new SpriteBatch();img = new Texture("badlogic.jpg");tools.showInterAd();tools.showBanner();}在IOS項目中實現該介面並寫入傳入
public class IOSLauncher extends IOSApplication.Delegate implements ITools{private static final String AD_UNIT_ID = "ca-app-pub-1743332321423234/7283499900";static IOSLauncher instance;@Overrideprotected IOSApplication createApplication() {IOSApplicationConfiguration config = new IOSApplicationConfiguration();return new IOSApplication(new GdxGame(instance), config);}public static void main(String[] argv) {instance = new IOSLauncher();NSAutoreleasePool pool = new NSAutoreleasePool();UIApplication.main(argv, null, IOSLauncher.class);pool.close();}@Overridepublic void showInterAd() {final GADInterstitial interstitial = new GADInterstitial(AD_UNIT_ID); interstitial.setDelegate(new GADInterstitialDelegateAdapter(){ @Override public void didReceiveAd(GADInterstitial ad) { super.didReceiveAd(ad); interstitial.present(((IOSApplication) Gdx.app).getUIViewController()); } @Override public void didFailToReceiveAd(GADInterstitial ad, GADRequestError error) { Gdx.app.log("xxx", error.getCode() + ""); super.didFailToReceiveAd(ad, error); } }); GADRequest request = GADRequest.create(); List<String> devices = new ArrayList<String>(); devices.add(GADRequest.GAD_SIMULATOR_ID); request.setTestDevices(devices); interstitial.loadRequest(request);}@Overridepublic void showBanner() { final GADBannerView mBannerView = new GADBannerView(GADAdSize.smartBannerPortrait()); mBannerView.setAdUnitID("ca-app-pub-1743332321423234/2574098708"); final UIViewController controller = ((IOSApplication) Gdx.app).getUIViewController(); GADRequest request = GADRequest.create(); List<String> devices = new ArrayList<String>(); devices.add(GADRequest.GAD_SIMULATOR_ID); mBannerView.setRootViewController(controller); controller.getView().addSubview(mBannerView); mBannerView.loadRequest(request);}}
應該能看懂吧? 不懂請留言
3.最重要的是環境搭建
因為自訂了一個.a檔案, 所以把libGADAdSizeWrapped.a檔案放入iOS項目的build/libs下面,並寫入xml
<libs> <lib>z</lib> <lib>build/libs/libGADAdSizeWrapped.a</lib> </libs>
把GoogleMobileAds.framework放入到build/libs裡面,並在xml指定framework尋找路徑(必須要加入這些framework才行喲)
<frameworkPaths><path>build/libs</path> </frameworkPaths> <frameworks> <framework>UIKit</framework> <framework>OpenGLES</framework> <framework>QuartzCore</framework> <framework>CoreGraphics</framework> <framework>OpenAL</framework> <framework>AudioToolbox</framework> <framework>AVFoundation</framework> <framework>CoreTelephony</framework> <framework>EventKit</framework> <framework>MessageUI</framework> <framework>EventKitUI</framework> <framework>SystemConfiguration</framework> <framework>CoreMedia</framework> <framework>GoogleMobileAds</framework> </frameworks> <weakFrameworks><framework>AdSupport</framework><framework>StoreKit</framework></weakFrameworks>
至此書寫完畢,可以運行了.......為了那個自訂.a我還去註冊了個開發人員帳號呢,....蛋疼 99刀大洋 心痛
如果您覺得對你有協助的話請點贊,謝謝!
源碼地址:https://github.com/tianqiujie/robovm-ios-bindings