简体   繁体   中英

Windows Phone - Store Universal App MessageDialog on launch

I want to show messagedialog when app starts. But in Universal app this code won't work. I want to ask user for review.

Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var composite = localSettings.Values["askforreview"];

if (composite == null)
{
    localSettings.Values.Add("askforreview", true);
    composite = true;
}
bool askforreview = Convert.ToBoolean(composite);
if (askforreview)
{
    MessageDialog dialog = new MessageDialog("some message");
    dialog .Commands.Add(new UICommand("Yes", ( command) =>
      {
          Launcher.LaunchUriAsync(CurrentApp.LinkUri);
      }));
    dialog.Commands.Add(new UICommand("Not Now"));
    await dialog .ShowAsync();
}

When I debug app, I always get an error "a.ShowAsnyc" statement. Program stops in App.gics's this statement.

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

This type of exception (UnauthorizedAccessException - Access Denied) when it comes to MessageDialogs usually happens when you already have one MessageDialog opened when you try to open another one.

I was able to get your code to work on my side in both page constructor (without the await, though), and in page loaded async event handler. But if I tried to do it in two places one after another, it would throw an exception, for the reason mentioned above.

So, please check that you don't have another MessageDialog opened when you try to show this one. Did you perhaps leave this code in both the page constructor and the app launched event handler? That might cause it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM