微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决有没有办法修复使用 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 举报,一经查实,本站将立刻删除。