[英]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.