我们如何在 xamarin 中将 AppDelegate class 添加到 AppDelegate.cs?

How can we add AppDelegate class to AppDelegate.cs in xamarin?

我正在 xamarin 上创建一个演示项目,我需要在其中将 AppDelegate class 添加到现有 AppDelegate.cs 文件,如下所述。由于我对这种事情很陌生,如果你能在这方面指导我就太好了。

class AppDelegate: NSObject, UIApplicationDelegate {

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        // Your code.
        return true
    }
}

您可以在 Xamarin 项目的 AppDelegate.cs 中覆盖 OpenUrl 以提供该功能

namespace yourapp.host.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
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            return base.FinishedLaunching(app, options);
        }

        public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
        {
            // Your code.

            return true;
        }
    }
}