根據微軟的文檔,你可以處理的應用程序的URI,此代碼如何處理UWP應用程序的URI使用Windows模板工作室
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
}
}
但是,這是當應用程序是默認的模板創建。我與Windows模板Studio和目前的地方UWP項目怡創,我猜想把這些代碼在現在
protected override async void OnActivated(IActivatedEventArgs args)
{
await ActivationService.ActivateAsync(args);
}
從而導致這個..
public async Task ActivateAsync(object activationArgs)
{
if (IsInteractive(activationArgs))
{
// Initialize things like registering background task before the app is loaded
await InitializeAsync();
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (Window.Current.Content == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
Window.Current.Content = _shell;
NavigationService.Frame.NavigationFailed += (sender, e) =>
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
};
NavigationService.Frame.Navigated += OnFrameNavigated;
if (SystemNavigationManager.GetForCurrentView() != null)
{
SystemNavigationManager.GetForCurrentView().BackRequested += OnAppViewBackButtonRequested;
}
}
}
var activationHandler = GetActivationHandlers().FirstOrDefault(h => h.CanHandle(activationArgs);
if (activationHandler != null)
{
await activationHandler.HandleAsync(activationArgs);
}
if (IsInteractive(activationArgs))
{
var defaultHandler = new DefaultLaunchActivationHandler(_defaultNavItem);
if (defaultHandler.CanHandle(activationArgs))
{
await defaultHandler.HandleAsync(activationArgs);
}
// Ensure the current window is active
Window.Current.Activate();
// Tasks after activation
await StartupAsync();
}
}
請,如果有人使用了之前的Windows模板工作室。請告訴我如何處理此代碼中的Uri。我不知道該把它放在哪裏。目前,我的應用程序從Uri發佈時啓動到空白頁面
我認爲[this](https://github.com/Microsoft/WindowsTemplateStudio/blob/master/docs/activation.md)可能會有所幫助。 – CoCaIceDew