简体   繁体   English

WindowsAppSDK 没有 ProtocolActivatedEventArgs

[英]WindowsAppSDK doesnt have ProtocolActivatedEventArgs

I am trying to handle protocol activation and as per docs I should handle all of that within OnLaunched method so that is what I am trying to do here, but Microsoft.Windows.AppLifecycle.ProtocolActivatedEventArgs doesnt exist.我正在尝试处理协议激活,根据文档,我应该在OnLaunched方法中处理所有这些,这就是我在这里尝试做的事情,但是Microsoft.Windows.AppLifecycle.ProtocolActivatedEventArgs不存在。

在此处输入图像描述

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    var activatedArgs = AppInstance.GetCurrent().GetActivatedEventArgs();
    var e = args.UWPLaunchActivatedEventArgs;
    InitializeRootFrame(e);
    if (activatedArgs.Kind is ExtendedActivationKind.Launch)
    {
        if (!e.PrelaunchActivated)
        {
            if (RootFrame.Content == null)
            {
                RootFrame.Navigate(typeof(LoginPage), e.Arguments);
            }
            Window.Current.Activate();
        }
    }
    else //Launched by some other means other than normal launching
    {
        try
        {
            if (activatedArgs.Kind is ExtendedActivationKind.Protocol && activatedArgs is Microsoft.Windows.AppLifecycle.ProtocolActivatedEventArgs eventArgs)
            {
                //var a = activatedArgs.Data as ProtocolActivatedEventArgs;
                var queryParameters = HttpUtility.ParseQueryString(activatedArgs.Data.Uri.Query);
                PocessQueryForToken(queryParameters);
            }
        }
        catch (Exception)
        {
        }
        finally
        {
            RootFrame.Navigate(typeof(LoginPage));
            Window.Current.Activate();
            HasLaunched = true;
        }
    }
    HasLaunched = true;
}

There is only a AppActivationArguments Class in the Microsoft.Windows.AppLifecycle NameSpace . Microsoft.Windows.AppLifecycle NameSpace中只有一个AppActivationArguments Class So the behavior you got is expected because you are looking for a class that doesn't even exist.所以你得到的行为是预期的,因为你正在寻找一个甚至不存在的 class。

Based on the document for AppActivationArguments , we could know that the activatedArgs we got contains a data object which has one of the following data types, depending on the activation type specified by the Kind property.根据AppActivationArguments的文档,我们可以知道我们得到的activatedArgs包含一个数据 object,它具有以下数据类型之一,具体取决于 Kind 属性指定的激活类型。

  • File ->IFileActivatedEventArgs文件->IFileActivatedEventArgs
  • Protocol ->IProtocolActivatedEventArgs协议 -> IProtocolActivatedEventArgs
  • StartupTask ->IStartupTaskActivatedEventArgs启动任务->IStartupTaskActivatedEventArgs

The IProtocolActivatedEventArgs should be the thing that we are looking for. IProtocolActivatedEventArgs应该是我们正在寻找的东西。 The document here- ProtocolActivatedEventArgs Class shows that this Class comes from the Windows.ApplicationModel.Activation Namespace .此处的文档ProtocolActivatedEventArgs Class显示此 Class 来自Windows.ApplicationModel.Activation 命名空间

So the code should looks like this:所以代码应该是这样的:

    protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
    {
        var eventargs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
        if (eventargs.Kind is ExtendedActivationKind.Protocol && eventargs.Data is Windows.ApplicationModel.Activation.ProtocolActivatedEventArgs)
        {
            ProtocolActivatedEventArgs ProtocolArgs = eventargs.Data as ProtocolActivatedEventArgs;
            var uri = ProtocolArgs.Uri;
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM