Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AdMob没有在我的应用程序上显示横幅广告为什么?_C#_Xamarin_Xamarin.forms_Admob - Fatal编程技术网

C# AdMob没有在我的应用程序上显示横幅广告为什么?

C# AdMob没有在我的应用程序上显示横幅广告为什么?,c#,xamarin,xamarin.forms,admob,C#,Xamarin,Xamarin.forms,Admob,所以我尝试在我的项目中实现AdMob,但我的广告没有出现,我也不知道为什么。 我在网上跟踪一个向导,在这一点上我似乎找不到,但是当他们做的时候,它工作得很好,我遵循了所有的步骤,我开始考虑它可能是XAMARIN,但我不确定。 我有一个AdMobRenderer.cs,看起来像这样 using Google.MobileAds; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS;

所以我尝试在我的项目中实现AdMob,但我的广告没有出现,我也不知道为什么。 我在网上跟踪一个向导,在这一点上我似乎找不到,但是当他们做的时候,它工作得很好,我遵循了所有的步骤,我开始考虑它可能是XAMARIN,但我不确定。 我有一个AdMobRenderer.cs,看起来像这样

    using Google.MobileAds;
    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;

    namespace AdMobTestProject.iOS
    {
        public class AdMobRenderer : ViewRenderer
        {
//hiding the key for this question
            private const string adMobId = "ca-app-pub-xxxxxx/xxxxxxx";
            private BannerView adView;
            private bool viewOnScreen;

            protected override void OnElementChanged(ElementChangedEventArgs<View> e)
            {
                base.OnElementChanged(e);
                if (e.NewElement == null)
                    return;
                if (e.OldElement == null)
                {
                    adView = new BannerView(AdSizeCons.SmartBannerPortrait)
                    {
                        AdUnitID = adMobId,
                        RootViewController = UIApplication.SharedApplication.Windows[0].RootViewController
                    };

                    adView.AdReceived += (sender, args) =>
                    {
                        if (!viewOnScreen)
                        {
                            this.AddSubview(adView);
                        }

                        viewOnScreen = true;
                    };
                    Request request = Request.GetDefaultRequest();
                    adView.LoadRequest(request);
                    base.SetNativeControl(adView);
                }
            }

            public AdMobRenderer()
            {

            }
        }
    }
我错过什么了吗?为什么在我将应用程序部署到我的设备时,它没有显示任何内容?iphone7。
我正在使用Xamarin.Forms

检查adview的可用空间不应小于360像素宽,因此检查页面的主布局(如果有页边距)并删除它们。 作为线索,检查VisualStudio中的“生成输出”窗口,它将显示广告是否已加载,并显示广告加载后不可见的原因。 在您的示例中,删除WidthRequest


这是以后搜索的延迟回复。

尝试将adMobId更改为测试广告id

(ca-app-pub-3940256099942544/630978111)


我也有同样的问题,如果我导航到另一个页面并返回,我的广告就会出现。

有例外吗?在您的“我有一个AdMobRenderer”中,您是否检查过任何空指针?没有异常,是的,没有问题。您能够查看测试广告吗?捕获日志并在您的问题中进行更新(日志不需要是异常,而是来自admob的响应)。同时检查屏幕上的广告屏蔽设置phone@AmodGokhale我尝试过使用测试广告,但什么都没有,admob日志是空的,我的手机上没有任何锁定。日志中应该有一些东西是因为没有显示广告。你能尝试添加不同的广告id吗?请确保你添加的是广告id,而不是应用id(最常见的错误)来自评论:嗨,虽然链接是分享知识的好方法,但如果将来它们被破坏了,它们不会真正回答问题。在回答中添加回答问题的链接的基本内容。如果内容太复杂或太大而不适合此处,请描述建议解决方案的总体思路。请记住始终保留原始解决方案网站的链接引用。见:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:AdMobTestProject"
             x:Class="AdMobTestProject.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
        <local:AdMobView WidthRequest="320" HeightRequest="50"></local:AdMobView>
    </StackLayout>

</ContentPage>
namespace AdMobTestProject
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }
    }

    public class AdMobView : ContentView
    {
        public AdMobView()
        {

        }
    }
}