Last active
December 22, 2015 18:39
-
-
Save m-gagne/6514536 to your computer and use it in GitHub Desktop.
Windows 8 C# code sample that asks for a review of the app after 5 launches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------------------------------------------- | |
// Ask for a review after 5 starts of the Application | |
// -------------------------------------------------- | |
// Variable to hold the number of time the app started | |
int startedCount = 0; | |
// Check if the variable was stored in the Roaming Settings before | |
if (Windows.Storage.ApplicationData.Current.RoamingSettings.Values.ContainsKey("startedCount")) | |
{ | |
// If so, read it in the variable | |
startedCount = (int)Windows.Storage.ApplicationData.Current.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 | |
Windows.Storage.ApplicationData.Current.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 [App Name] for a while now, would you like to review this app?", | |
"Please review my app"); | |
// Build the 2 potential responses using the Commands collection | |
bool? reviewresult = null; | |
md.Commands.Add(new Windows.UI.Popups.UICommand( | |
"Yes", | |
new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = true))); | |
md.Commands.Add(new Windows.UI.Popups.UICommand( | |
"No", | |
new Windows.UI.Popups.UICommandInvokedHandler((cmd) => reviewresult = false))); | |
// Display the MessageBox asyncronously. ** Note that you may have to add the async | |
// keyword to the OnLaunched event definition above | |
await md.ShowAsync(); | |
// If the user agrees | |
if (reviewresult == true) | |
{ | |
// Find the FamilyName of the app package | |
string familyName = Package.Current.Id.FamilyName; | |
// Navigate to the store Review Page for the Application | |
await Windows.System.Launcher.LaunchUriAsync(new Uri( | |
string.Format("ms-windows-store:REVIEW?PFN={0}", | |
familyName))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment