我试图在他们第五次打开我的应用程序时出现应用评论提示,但我似乎没有任何运气。我已尝试在此网站上使用该代码,但它对我不起作用。还有其他任何人都知道吗?
async protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
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();
// Set the default language
rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
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;
}
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);
}
// Ensure the current window is active
Window.Current.Activate();
int started = 0;
if (Windows.Storage.ApplicationData.Current.RoamingSettings.Values.ContainsKey("started"))
{
started = (int)Windows.Storage.ApplicationData.Current.RoamingSettings.Values["started"];
}
started++;
Windows.Storage.ApplicationData.Current.RoamingSettings.Values["started"] = started;
if (started == 3)
{
var md = new Windows.UI.Popups.MessageDialog("Thank you for using this app?", "Please review my app");
bool? reviewresult = null;
md.Commands.Add(new Windows.UI.Popups.UICommand("OK", new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = true)));
md.Commands.Add(new Windows.UI.Popups.UICommand("Cancel", new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = false)));
await md.ShowAsync();
if (reviewresult == true)
{
string familyName = Package.Current.Id.FamilyName;
await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format("ms-windows-store:REVIEW?PFN={0}", familyName)));
}
}
}
答案 0 :(得分:2)
您在应用初始化到可以启动MessageDialog的位置之前调用它。
如果你查看你正在复制的文章,那么在调用Window.Current.Activate()之后它会说新的代码放在OnLaunched方法的底部,而不是在OnLaunched方法的开头。
如果您这样做,则对话框可以根据需要运行。