通过单击 SecondaryTile 检查用户是否来到应用程序
Check if user came to app by clicking on SecondaryTile
我想知道用户是否通过点击 SecondaryTile 打开了应用程序(以及点击了哪个)。
现在我有了 OnNavigatedTo 方法:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
if (!String.IsNullOrEmpty(e.Parameter.ToString()))
{
//e.Parameter is not null, LiveTile was used
//do something
}
else
{
//No of SecondaryTiles were clicked
}
}
这当然有效,但前提是应用程序之前已关闭。但是当应用程序之前打开,在后台运行并且用户点击 LiveTile 时,应用程序正在显示但没有执行此方法。
我该如何处理这种情况?
MSDN: Override the OnLaunched method to perform any general app initialization that should occur only when the user launches your app normally (for example, by tapping the app tile).
您应该覆盖或更新 OnLaunched 事件以跟踪应用激活时刻并分析相应的参数(app.xaml.cs
文件)。
简而言之,如果您查看 OnNavigatedTo
事件是如何发生的——它来自检查 rootFrame
的内容是否已经存在的 OnLaunched
事件:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
...
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
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
...
}
正如您在场景中想象的那样,这不是真的,因此导航事件永远不会发生。
我想知道用户是否通过点击 SecondaryTile 打开了应用程序(以及点击了哪个)。
现在我有了 OnNavigatedTo 方法:
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
if (!String.IsNullOrEmpty(e.Parameter.ToString()))
{
//e.Parameter is not null, LiveTile was used
//do something
}
else
{
//No of SecondaryTiles were clicked
}
}
这当然有效,但前提是应用程序之前已关闭。但是当应用程序之前打开,在后台运行并且用户点击 LiveTile 时,应用程序正在显示但没有执行此方法。
我该如何处理这种情况?
MSDN: Override the OnLaunched method to perform any general app initialization that should occur only when the user launches your app normally (for example, by tapping the app tile).
您应该覆盖或更新 OnLaunched 事件以跟踪应用激活时刻并分析相应的参数(app.xaml.cs
文件)。
简而言之,如果您查看 OnNavigatedTo
事件是如何发生的——它来自检查 rootFrame
的内容是否已经存在的 OnLaunched
事件:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
...
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
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
...
}
正如您在场景中想象的那样,这不是真的,因此导航事件永远不会发生。