【发布时间】:2014-10-23 13:15:12
【问题描述】:
我正在为我的 iOS 应用程序使用 RoboVM 绑定来显示 AdMob 插页式广告。当我关闭插页式广告时,我失去了所有的触摸控制。有没有办法检测广告被关闭,以便我可以将触摸恢复到游戏中?还是有更好的方法来实现插页式广告?下面是我的代码:
public class IOSLauncher extends IOSApplication.Delegate implements IActivityRequestHandler{
private static final Logger log = new Logger(IOSLauncher.class.getName(), Application.LOG_DEBUG);
private IOSApplication iosApplication;
//interstitial
private static final String INTERSTITIAL_AD = "MY_AD_ID";
private GADInterstitial interstitial;
private UIWindow window;
private UIViewController rootViewController;
@Override
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.orientationLandscape = true;
config.orientationPortrait = false;
iosApplication = new IOSApplication(new PaperPig(this), config);
return iosApplication;
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
@Override
public void initializeAds() {
intializeInterstitial();
}
public void intializeInterstitial () {
rootViewController = new UIViewController();
interstitial = new GADInterstitial();
interstitial.setAdUnitID(INTERSTITIAL_AD);
interstitial.setDelegate(new GADInterstitialDelegateAdapter() {
@Override
public void didReceiveAd (GADInterstitial ad) {
System.out.println("Did receive ad.");
}
@Override
public void didFailToReceiveAd (GADInterstitial ad, GADRequestError error) {
System.out.println(error.description());
System.out.println(error.getErrorCode());
}
});
window = new UIWindow(UIScreen.getMainScreen().getBounds());
window.setRootViewController(rootViewController);
window.addSubview(rootViewController.getView());
interstitial.loadRequest(GADRequest.create());
}
@Override
public void showOrLoadInterstital() {
if (interstitial.isReady()) {
if (rootViewController == null) {
rootViewController = new UIViewController();
}
if (window == null) {
window = new UIWindow(UIScreen.getMainScreen().getBounds());
window.setRootViewController(rootViewController);
}
window.makeKeyAndVisible();
interstitial.present(rootViewController);
}
//将触摸返回到游戏
//UIApplication.getSharedApplication().getKeyWindow().setRootViewController(rootViewController);
}
}
【问题讨论】:
-
您可以通过覆盖 GADInterstitialDelegateAdapter 中的 didDismissScreen 来检测关闭。你在那一点上做的事情也是我被卡住的地方。如果我解决了,我会告诉你的。
标签: ios admob ads interstitial robovm