Skip to content

Instantly share code, notes, and snippets.

@m-gagne
Created September 11, 2013 02:47
Show Gist options
  • Save m-gagne/6518769 to your computer and use it in GitHub Desktop.
Save m-gagne/6518769 to your computer and use it in GitHub Desktop.
Windows 8 HTML5/Javascript code sample that asks for a review of the app after 5 launches
// Ask for a review after 5 starts of the Application
// Variable to hold the number of time the app started
var startedCount = 0;
// Check if the
variable was stored in the Roaming Settings before
var appData = Windows.Storage.ApplicationData.current;
var roamingSettings = appData.roamingSettings;
if (roamingSettings.values.hasKey("startedCount"))
{
// If so, read it in the variable
startedCount = roamingSettings.values["startedCount"];
}
// Increment the count by 1
startedCount++;
// And then save it in the Roaming Settings. Note that if the value pair was not
// created before, the method will create it automatically
roamingSettings.values["startedCount"] = startedCount;
// If the app was started 5 times
if (startedCount == 5)
{
// Create a MessageDialog requesting a review
var md = new Windows.UI.Popups.MessageDialog(
"Thank you for using Grid App for a while now, would you like to review this app?",
"Please review my app");
// Build the 2 potential responses using the Commands collection
md.commands.append(new Windows.UI.Popups.UICommand(
"Yes",
function (command) {
// Find the FamilyName of the app package
var familyName = Windows.ApplicationModel.Package.current.id.familyName;
// Navigate to the store Review Page for the Application
var uri = new Windows.Foundation.Uri("ms-windows-store:REVIEW?PFN={0}", familyName);
Windows.System.Launcher.launchUriAsync(uri);
}));
md.commands.append(new Windows.UI.Popups.UICommand(
"No"));
// Set the command that will be invoked by default
md.defaultCommandIndex = 0;
// Set the command to be invoked when escape is pressed
md.cancelCommandIndex = 1;
// Display the MessageBox asyncronously.
md.showAsync();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment