0

I have followed the instructions as found in the documentation; however, when I launch my app using the specified protocol my-protocol:// (typed into a web browser), the app will launch but then it just stays on the splash screen, as if the navigation fails to do anything:

Code Example:

// MyApp.UWP/App.xaml.cs
protected override void OnActivated(IActivatedEventArgs args)
  {
      if (args.Kind == ActivationKind.Protocol)
      {
         ProtocolActivatedEventArgs eventArgs = 
             args as ProtocolActivatedEventArgs;

         // TODO: Decide where to navigate, but for now just go to main page

         Frame rootFrame = Window.Current.Content as Frame;
         rootFrame.Navigate(typeof(MainPage), args);
      }
   }

Is there something obvious that I am doing wrong? Perhaps there is a better way to handle navigation? Or perhaps there is something that I overlooked?

Edit

This is particularly hard to troubleshoot, since I can't just run with debug in visual studio. To test it out I actually have to launch it from the my-protocol://, which is not connected to the debugger.

Is there a way to debug this when launched from the url / protocol?

ToddBFisher
  • 11,370
  • 8
  • 38
  • 54

1 Answers1

2

I could reproduce your issue. @kennyzx's suggestion was correct. You would first need to do judgement before navigating.

Please refer to the following code sample for reference.

protected override void OnActivated(IActivatedEventArgs args)
{
        base.OnActivated(args);
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs =
                args as ProtocolActivatedEventArgs;

            // TODO: Decide where to navigate, but for now just go to main page

            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            {
                rootFrame = new Frame();
            }
            Window.Current.Content = rootFrame;
            rootFrame.Navigate(typeof(MainPage), args);
            Window.Current.Activate();
        }
}
Xie Steven
  • 8,544
  • 1
  • 9
  • 23
  • I tried this solution ... it did not work for me. Now the app simply crashes, instead of stops at the splash screen. I will work on in some more and report back. – ToddBFisher Jun 21 '18 at 22:28
  • 2
    My above code worked well on my side. If it did not work for you, there might be some other issues in your code. It's easy to debug in this scenario. "Right click your project in visual studio - select properties - select Debug - see start action - select Do not launch, but debug my code when it starts".Then start to debug on your local machine, your app will not launch, you type your app's protocol in browser to active your app. – Xie Steven Jun 25 '18 at 06:29
  • Wow, that option is a life saver in this scenario ... thank you so much for sharing it. – ToddBFisher Jun 25 '18 at 16:48
  • I was missing the `Window.Current.Activate();` line, works now, thanks! – ToddBFisher Jun 25 '18 at 16:58