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

Time:03-08

I am creating a demo project on xamarin in which I need to add an AppDelegate class as mentioned below to the existing AppDelegate.cs file. As I am new to this kind of thing it would be great if you can guild me on this.

class AppDelegate: NSObject, UIApplicationDelegate {

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

CodePudding user response:

You can override OpenUrl in AppDelegate.cs in your Xamarin project to provide that functionality

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;
        }
    }
}
  • Related