[英]I couldn't create AdMob banner in my Xamarin.ios
我正在尝试在Xamarin iOS项目中添加AdMob横幅。 您可以在下面看到我的代码。
public void AddAdvirtesement()
{
var adView = new BannerView();
adView.Frame = new CGRect(0, View.Bounds.Height - 50, View.Bounds.Width, 50);
adView.BackgroundColor = UIColor.Gray;
adView.AdUnitID = bannerId;
adView.RootViewController = this;
View.AddSubview(adView);
var request = Request.GetDefaultRequest();
string[] testdevices = new string[2];
//testdevices[0] = Request.SimulatorId.ToString();
//testdevices[1] = "b5f64ec8566bf1a5cd1cb853d7106aa7";
request.TestDevices = testdevices;
adView.LoadRequest(request);
}
我得到以上代码输出:
2016-12-11 22:25:42.659 betcluev4 [9220:627724]您当前正在使用SDK的7.11.0版本。 请考虑将您的SDK更新到最新的SDK版本,以获取最新的功能和错误修复。 可以从.......下载最新的SDK。
但我已经拥有最新的Firebase SDK(7.11.0)。 有什么想法吗?
检查项目中所需的FireBase的plist 配置 ,以及下面的示例代码
配置
将您的GoogleService-Info.plist文件下载到计算机中后,请在Xamarin Studio中执行以下步骤:
将GoogleService-Info.plist
文件添加到您的应用程序项目。
通过右键单击/构建操作,将GoogleService-Info.plist
构建操作行为设置为Bundle Resource
。
打开GoogleService-Info.plist
文件,并将IS_ADS_ENABLED
值更改为Yes
。
将以下代码行添加到应用程序中的某处,通常是在AppDelegate的FinishedLaunching
方法中(不要忘记导入Firebase.Analytics
命名空间):
App.Configure ();
样例代码
using Google.MobileAds;
const string bannerId = "<Get your ID at google.com/ads/admob>";
BannerView adView;
bool viewOnScreen = false;
public void AddBanner ()
{
// Setup your BannerView, review AdSizeCons class for more Ad sizes.
adView = new BannerView (size: AdSizeCons.Banner, origin: new CGPoint (0, 0)) {
AdUnitID = bannerId,
RootViewController = this
};
// Wire AdReceived event to know when the Ad is ready to be displayed
adView.AdReceived += (object sender, EventArgs e) => {
if (!viewOnScreen) {
View.AddSubview (adView);
viewOnScreen = true;
}
};
var request = Request.GetDefaultRequest ();
// Requests test ads on devices you specify. Your test device ID is printed to the console when
// an ad request is made. GADBannerView automatically returns test ads when running on a
// simulator. After you get your device ID, add it here
request.TestDevices = new [] { Request.SimulatorId.ToString () };
// Request an ad
adView.LoadRequest (request);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.