Access ViewController in DependencyService to present MFMailComposeViewController

后端 未结 5 2075
失恋的感觉
失恋的感觉 2020-12-15 23:15

How can i access the ViewController in my DependencyService to present a MFMailComposeViewController? I tried using Application.Context but this seems to be only working on

5条回答
  •  旧时难觅i
    2020-12-15 23:46

    Just for a reference. It took me some time to figure it out how to launch it from modal window.

    Here comes the solution:

    var rootController = ((AppDelegate)(UIApplication.SharedApplication.Delegate)).Window.RootViewController.PresentedViewController;
    var navcontroller = rootController as UINavigationController;
    if (navcontroller != null)
        rootController = navcontroller.VisibleViewController;
    rootController.PresentViewController (controller, true, null);
    

提交回复
热议问题