Open ViewModel from Appdelegate

徘徊边缘 提交于 2019-12-13 00:24:05

问题


I am trying to open a specific view in my Xamarin.Ios-Project via a Web-Url. The url-scheme works fine and i also check the url in the AppDelegate class as shown below:

[Register("AppDelegate")]
public partial class AppDelegate : MvxApplicationDelegate
{
    // other methods ...

    public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        if (url == null) return false;

        var uri = new Uri(url.ToString());
        if(uri.Host.Equals("myscheme-host"))
        {
            var param = GetParameters(uri);

            // What can i do here?
            ShowViewModel<MyViewModel>();

            return true;
        }
    }
}

How can I show my Viewmodel from this point? I tried to set a value in a static class and check it when the next view loads. But when the app is in the background bevore the user clicked the Url-Scheme-Link, no event (ViewDidLoad, ViewWillAppear, ..) will raise.

Any help is appreciated. Thanks a lot


回答1:


I am using a custom scheme to start an application (something like myscheme-host:xxxx) so what I would write on the OpenUrl is something like this:

    public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
    {
        if (url.AbsoluteString.StartsWith("myscheme-host:"))
        {
            this.window.RootViewController = new MySchemeViewController();

In your case you would probably create a new view model from the "xxxx" parameters and pass that view model to a view controller (whether that is straight from the code or through a resolver that pairs the view model with a controller).



来源:https://stackoverflow.com/questions/25660904/open-viewmodel-from-appdelegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!