简体   繁体   English

我无法在Xamarin.ios中创建AdMob横幅

[英]I couldn't create AdMob banner in my Xamarin.ios

I'm trying to add AdMob banner in my Xamarin iOS project. 我正在尝试在Xamarin iOS项目中添加AdMob横幅。 You can see my code below. 您可以在下面看到我的代码。

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);
        }

i get this output above code: 我得到以上代码输出:

2016-12-11 22:25:42.659 betcluev4[9220:627724] You are currently using version 7.11.0 of the SDK. 2016-12-11 22:25:42.659 betcluev4 [9220:627724]您当前正在使用SDK的7.11.0版本。 Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes. 请考虑将您的SDK更新到最新的SDK版本,以获取最新的功能和错误修复。 The latest SDK can be downloaded from ....... 可以从.......下载最新的SDK。

but I already have the latest SDK of Firebase (7.11.0). 但我已经拥有最新的Firebase SDK(7.11.0)。 Any thoughts? 有什么想法吗?

Check out the plist configurations for FireBase that are needed in your project , and the sample code below 检查项目中所需的FireBase的plist 配置 ,以及下面的示例代码

Configurations 配置

Once you have your GoogleService-Info.plist file downloaded in your computer, do the following steps in Xamarin Studio: 将您的GoogleService-Info.plist文件下载到计算机中后,请在Xamarin Studio中执行以下步骤:

Add GoogleService-Info.plist file to your app project. GoogleService-Info.plist文件添加到您的应用程序项目。

Set GoogleService-Info.plist build action behaviour to Bundle Resource by Right clicking/Build Action. 通过右键单击/构建操作,将GoogleService-Info.plist构建操作行为设置为Bundle Resource

Open GoogleService-Info.plist file and change IS_ADS_ENABLED value to Yes . 打开GoogleService-Info.plist文件,并将IS_ADS_ENABLED值更改为Yes

Add the following line of code somewhere in your app, typically in your AppDelegate's FinishedLaunching method (don't forget to import Firebase.Analytics namespace): 将以下代码行添加到应用程序中的某处,通常是在AppDelegate的FinishedLaunching方法中(不要忘记导入Firebase.Analytics命名空间):

App.Configure ();

Sample Code 样例代码

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM