每当用户点击推送通知以演示概念时,我都会尝试启动显式页面。
此代码过去曾经(去年)工作过,但我不记得我在过渡期间改变了它停止了工作。
以下是app.xaml的代码。
private async void AcquirePushChannel()
{
try
{
CurrentChannel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
}
catch (Exception)
{
new MessageDialog("Cannot Contact Azure Server", "Operation Timed Out");
}
IMobileServiceTable<Registrations> registrationsTable = App.MobileService.GetTable<Registrations>();
var registration = new Registrations { Handle = CurrentChannel.Uri };
await registrationsTable.InsertAsync(registration);
}
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected async override void OnLaunched(LaunchActivatedEventArgs args)
{
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();
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
string launchstring = args.Arguments;
if (!string.IsNullOrEmpty(launchstring))
{
rootFrame.Navigate(typeof(InstructionSetBlue));
}
AcquirePushChannel();
// Ensure the current window is active
Window.Current.Activate();
}
这段代码启动特定页面。
if (!string.IsNullOrEmpty(launchstring))
{
rootFrame.Navigate(typeof(InstructionSetBlue));
}