我关注了https://github.com/lilili87222/admob-for-flash
我仍然看不到admob ane的广告。
步骤:
1.Init Admob ANE
将Admob ane添加到air项目的构建路径,并在脚本文件中添加以下代码
import so.cuo.platform.admob.*;
Admob.getInstance().initAdmobSDK("your admob app ID");
2。在Adobe Air App中添加Admob横幅
这是显示admob标语所需的最少代码。
Admob.getInstance().showBanner("your banner ID ",AdmobSize.BANNER_320x50,AdmobPosition.BOTTOM_CENTER);
AdmobPosition类指定放置横幅的位置。 AdmobSize指定要显示的尺寸横幅
3。移除横幅 默认情况下,横幅是可见的。要隐藏横幅,
Admob.getInstance().hideBanner();
4.Admob ANE显示非页内广告
这是将非页内广告集成到Air ios应用或flex android应用中的最少代码。
Admob.getInstance().cacheInterstitial("your Interstitial ID ");
在显示插页式广告之前,先检查其是否已加载:
if (Admob.getInstance().isInterstitialReady()) {
Admob.getInstance().showInterstitial();
}
5。自定义Admob标语广告尺寸
除了AdSize上的常量外,您还可以创建自定义尺寸:
//Create a 320x250 banner.
AdSize adSize = new AdSize(320, 250);
Admob.getInstance().showBannerAbsolute(adSize,0,30);
6。设置Admob目标参数
如果您希望广告针对儿童:
extraParam=new ExtraParameter();
extraParam.testDeviceID="true";
extraParam.isChildApp=true;//if is tagForChildDirectedTreatment,set true
extraParam.isDesignedForFamilies=true;
extraParam.nonPersonalizedAds=true;//if want to load non Personalized ads set true
Admob.getInstance().showBanner("Your banner ID",AdmobSize.BANNER_320x50,AdmobPosition.BOTTOM_CENTER,80,extraParam);
7.Ad Events
横幅广告和非页内广告都包含许多您可以注册的广告事件。 要在插页式广告上设置广告事件并在广告成功加载后显示插页式广告:
Admob.getInstance().addEventListener(AdmobEvent.onInterstitialReceive, onAdEvent);
private function onAdEvent(event:AdmobEvent):void
{
if (event.type == AdmobEvent.onBannerReceive)
{
trace(event.instanceName,event.data.width, event.data.height);
}
if (event.type == AdmobEvent.onInterstitialReceive)
{
Admob.getInstance().showInterstitial();
}
}
8.Admob奖励视频
视频API与非页内广告类似
要在视频上设置广告事件并在广告成功加载后显示视频,请执行以下操作:
if(admob.isVideoReady()){
admob.showVideo();
}else{
admob.cacheVideo(videoID);
}
Admob.getInstance().addEventListener(AdmobEvent.onVideoReceive, onVideoEvent);
private function onVideoEvent(event:AdmobEvent):void
{
if (event.type == AdmobEvent.onVideoReceive)
{
trace("load video success,you can show video now");
}
}
9.IOS最低版本配置
admob需要ios 8及更高版本
<key>MinimumOSVersion</key>
<string>8.0</string>
简单的例子
<iPhone>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
<string>2</string>
</array>
<key>MinimumOSVersion</key>
<string>8.0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsForMedia</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
</dict>
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
10.android权限配置
admob 17必须提供元配置com.google.android.gms.ads.APPLICATION_ID。请用您的admob ID替换ca-app-pub-3940256099942544〜3347511713
<android>
<manifestAdditions><![CDATA[
<manifest android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent"/>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
]]></manifestAdditions>
</android>