有没有办法修复使用 Xamarin C#

问题描述

我尝试添加 AdMob,我认为错误来自更改 AppDelegate.cs 中的代码,但我不确定 100%。

我的代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using UIKit;

namespace WeatherLocationInfo.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application,as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window,load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method,or iOS will terminate your application.
        //
        [Obsolete]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
        public override bool FinishedLaunching(UIApplication app,NSDictionary options)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
        {
            Xamarin.Forms.Forms.Init();
            Google.MobileAds.MobileAds.Configure(AppConstants.AppId);
            LoadApplication(new App());

            return base.FinishedLaunching(app,options);
        }


   }
}

错误可能来自哪里?

我使用此链接 Xamarin Forms AdMob,当我下载该项目时,他工作。当我仅为 iOS 项目复制/粘贴和下载库时,我收到 Runtime.cs file not found. 有没有办法解决错误

Runtime.cs file not found

我有一个名为 AdMobVieWrenderer.cs文件,我认为错误来自那里或

appDelegate.cs

所以 AdMobVieWrenderer.cs 中的代码是:

using System.ComponentModel;
using Foundation;
using Google.MobileAds;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using WeatherLocationInfo.Controls;
using WeatherLocationInfo.iOS.Implementations;

[assembly: ExportRenderer(typeof(AdmobControl),typeof(AdMobVieWrenderer))]
namespace WeatherLocationInfo.iOS.Implementations
{
    [Protocol]
    public class AdMobVieWrenderer : VieWrenderer<AdmobControl,BannerView>
    {
        [System.Obsolete]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
        protected override void OnElementChanged(ElementChangedEventArgs<AdmobControl> e)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
        {
            base.OnElementChanged(e);
            if (Control == null)
            {
                SetNativeControl(CreateBannerView());
            }
        }

        [System.Obsolete]
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
        protected override void OnElementPropertyChanged(object sender,PropertyChangedEventArgs e)
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member
        {
            base.OnElementPropertyChanged(sender,e);
            Control.AdUnitID = Element.AdUnitId;
        }

    [System.Obsolete]
    private BannerView CreateBannerView()
    {
        var bannerView = new BannerView(AdSizeCons.SmartBannerPortrait)
        {
            AdUnitID = Element.AdUnitId,RootViewController = GetVisibleViewController()
        };

        bannerView.LoadRequest(GetRequest());

        Request GetRequest()
        {
            var request = Request.GetDefaultRequest();
            return request;
        }

        return bannerView;
    }

    private UIViewController GetVisibleViewController()
    {
        var windows = UIApplication.SharedApplication.Windows;
        foreach (var window in windows)
        {
            if (window.RootViewController != null)
            {
                return window.RootViewController;
            }
        }
        return null;
    }
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)