2017-01-18 111 views
0

我使用本教程後的UWP應用程序的通知集線器:Getting started with Notification Hubs for Windows Universal Platform AppsAzure通知集線器UWP,UWP Toast通知不會啓動應用程序

如果我測試了Windows 8通知發送類似:

<?xml version="1.0" encoding="utf-8"?> 
<toast> 
<visual><binding template="ToastText01"> 
<text id="1">Test message</text> 
</binding> 
</visual> 
</toast> 

它的工作原理,如果我的通知點擊,它通過OnLaunched()方法打開的應用程序。但是,如果我發送一個特定UWP類似的通知:

<toast launch="app-defined-string"> 
<visual> 
<binding template="ToastGeneric"> 
    <text>Microsoft Company Store</text> 
    <text>New Halo game is back in stock!</text> 
</binding> 
</visual> 
<actions> 
<action activationType="foreground" content="See more details" arguments="details"/> 
<action activationType="background" content="Remind me later" arguments="later"/> 
</actions> 
</toast> 

的烤麪包的作品,但如果我點擊它,打開它的應用程序和OnLaunched()從來沒有所謂所以停留在spashscreen應用。

預先感謝您的幫助,

問候

回答

0

對於那些誰擁有了實現OnActivated同樣的問題,用Dave Smits回答:juste在App.xaml.cs文件中添加OnZctivated方法,並放置與OnLaunched方法相同的內容:

protected override async void OnLaunched(LaunchActivatedEventArgs e) 
    { 
     await OnLaunchedOrActivated(e); 
    } 

protected override async void OnActivated(IActivatedEventArgs e) 
    { 
     await OnLaunchedOrActivated(e); 
    } 

private async Task OnLaunchedOrActivated(IActivatedEventArgs e) 
    { 
     // Initialize things like registering background task before the app is loaded 

     Frame rootFrame = Window.Current.Content as Frame; 

     // Do not repeat app initialization when the Window already has content, 
     // just ensure that the window is active 
     if (rootFrame == null) 
     { 
      // Create a Frame to act as the navigation context and navigate to the first page 
      rootFrame = new Frame(); 

      rootFrame.NavigationFailed += OnNavigationFailed; 

      if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 
      { 
       // TODO: Load state from previously suspended application 
      } 

      // Place the frame in the current Window 
      Window.Current.Content = rootFrame; 
     } 

     // Handle toast activation 
     if (e is ToastNotificationActivatedEventArgs) 
     { 
      var toastActivationArgs = e as ToastNotificationActivatedEventArgs; 

      // If empty args, no specific action (just launch the app) 
      if (toastActivationArgs.Argument.Length == 0) 
      { 
       if (rootFrame.Content == null) 
        rootFrame.Navigate(typeof(MainPage)); 
      } 
      // Otherwise an action is provided 
      else 
      { 
       // Parse the query string 


       // See what action is being requested 

       // If we're loading the app for the first time, place the main page on the back stack 
       // so that user can go back after they've been navigated to the specific page 
       if (rootFrame.BackStack.Count == 0) 
        rootFrame.BackStack.Add(new PageStackEntry(typeof(MainPage), null, null)); 
      } 
     } 

     // Handle launch activation 
     else if (e is LaunchActivatedEventArgs) 
     { 
      var launchActivationArgs = e as LaunchActivatedEventArgs; 

      // If launched with arguments (not a normal primary tile/applist launch) 
      if (launchActivationArgs.Arguments.Length > 0) 
      { 
       // TODO: Handle arguments for cases like launching from secondary Tile, so we navigate to the correct page 
       throw new NotImplementedException(); 
      } 

      // Otherwise if launched normally 
      else 
      { 
       // If we're currently not on a page, navigate to the main page 
       if (rootFrame.Content == null) 
        rootFrame.Navigate(typeof(MainPage)); 
      } 
     } 

     else 
     { 
      // TODO: Handle other types of activation 
      throw new NotImplementedException(); 
     } 


     // Ensure the current window is active 
     Window.Current.Activate(); 
    }