从 Appdelegate 打开 ViewModel [英] Open ViewModel from Appdelegate
问题描述
我正在尝试通过 Web-Url 在我的 Xamarin.Ios-Project 中打开特定视图.url-scheme 工作正常,我还检查了 AppDelegate 类中的 url,如下所示:
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;
}
}
}
如何从这一点上显示我的 Viewmodel?我试图在静态类中设置一个值,并在下一个视图加载时检查它.但是,当应用在后台运行时,用户点击了 Url-Scheme-Link,则不会引发任何事件(ViewDidLoad、ViewWillAppear、..).
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
推荐答案
我正在使用自定义方案来启动一个应用程序(类似于 myscheme-host:xxxx),所以我会在 OpenUrl 上写下这样的内容:
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();
在您的情况下,您可能会从xxxx"参数创建一个新的视图模型并将该视图模型传递给视图控制器(无论是直接来自代码还是通过将视图模型与控制器配对的解析器).
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).
这篇关于从 Appdelegate 打开 ViewModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!