邀請使用者對你的 Windows Store App 評分 (App review & rating)


打開 App.xaml.cs 檔,先宣告以下兩個變數:

private DispatcherTimer m_DispatcherTime;
StorageFolder folder = ApplicationData.Current.LocalFolder; 

在 App() 中呼叫 loadInfo() 方法如以下:

public App()
{
      this.InitializeComponent();
      this.Suspending += OnSuspending;
      loadInfo();
}

最後實作 loadInfo(), m_DispatcherTime_Tick() 及 CommandInvokedHandler() 方法如以下:

private async void loadInfo()
{
    bool isExist = true;
    try
    {
        StorageFile isExistfile = await folder.GetFileAsync("isExist.dat");
    }
    catch (FileNotFoundException ex)
    {
        isExist = false;
    }
    if (!isExist)
    {
        m_DispatcherTime = new DispatcherTimer();
        m_DispatcherTime.Interval = new TimeSpan(0, 0, 0, 5);
        m_DispatcherTime.Tick += m_DispatcherTime_Tick;
        m_DispatcherTime.Start();
    }
}

#region rating timer

private async void m_DispatcherTime_Tick(object sender, object e)
{
    var dialog = new MessageDialog("請至市集給我們評份及建議。", "評分及建議");
    dialog.Commands.Add(new UICommand("Cancle", CommandInvokedHandler, 0));
    dialog.Commands.Add(new UICommand("Go", CommandInvokedHandler, 1));
    dialog.DefaultCommandIndex = 1;
    await dialog.ShowAsync(); m_DispatcherTime.Stop();
}

/// <summary>
/// Callback function for the invocation of the dialog commands.
/// </summary>
/// <param name="command">The command that was invoked.</param>
private async void CommandInvokedHandler(IUICommand command)
{
//Windows.System.Launcher.LaunchUriAsync(new Uri
//("ms-windows-store:REVIEW?PFN=Your package family name from the manifest"));
    if (command.Id.Equals(1))
    {
        StorageFile file = 
        await folder.CreateFileAsync("isExist.dat", 
        CreationCollisionOption.ReplaceExisting);
        Windows.System.Launcher.LaunchUriAsync
             (new Uri("ms-windows-store:REVIEW?PFN=
                9034Meng-RuTsai.OsakaMetroMapOffline_bygkn6mn9zr2y"));
    }
}
#endregion

黃色部份是 Windows Store App 的 family name (套件家族名稱), 可以在 manifest 檔中取得:

image

其實,邀請使用者至市集評分頁的關鍵之處,是使用 Windows 作業系統預設的 Protocol Activation。各位可以將以下直接貼在瀏覽器中作試驗。

ms-windows-store:REVIEW?PFN=9034Meng-RuTsai.OsakaMetroMapOffline_bygkn6mn9zr2y

最後,以上程式是以利用一個暫存檔 (isExist.dat) 來判斷是否要提醒使用者,此檔建立在使用者目錄下的 AppData 資料夾中,如:

C:\Users\[user name]\AppData\Local\Packages\972A5D21.43908557F4F45_tkaddggce39qp\LocalState\

如果想重覆測試,删掉 isExist.dat 檔即可。此檔記錄使用者是否有點擊 Go 的選項。

以下是執行畫面供參考:

image

使用者點擊 Go 的話:

image

Comments (0)

Skip to main content