2014-05-09 100 views
1

有一個名爲Web App Template(又名WAT - http://wat.codeplex.com/)的項目,允許您將Web應用程序打包爲Windows 8/Windows Phone 8應用程序。我已經完成了一個應用程序,現在我試圖添加「評價我的應用程序」功能。我看不到在哪裏/如果我可以注入代碼來添加這個組件。將「評價我的應用程序」添加到Web應用程序模板

我在這裏以下指南:http://developer.nokia.com/community/wiki/Implement_%22Rate_My_App%22_in_under_60_seconds

我被困在第5步 - 我在哪裏添加事件處理?沒有MainPage.xaml.cs,我沒有看到任何類似的文件。

我想象一下,WAT正在調用另一個庫來加載Web瀏覽器。有什麼方法可以將事件處理程序和方法注入到這個庫中?

+0

好的我已經找到了MainPage.xaml.cs的位置 - 在解決方案資源管理器中的MainPage.xaml下嵌套,所以我想我要弄明白了。 –

+0

對不起,但開發問題必須問在Stackoverflow。 –

回答

1

我建議不要在第一次打開應用程序時提示'評價我的應用程序',因爲應該給用戶一些時間來查看應用程序的外觀和功能。因此,保持應用程序啓動數量並要求在應用程序的第5次至第10次啓動後對應用程序進行評級將更有意義。此外,你應該檢查你是否已經提示用戶評價你的應用程序,如果沒有再次提示。 (否則,你會因'評價我的應用程序'而惹惱他們)

爲了達到這個目的,你應該首先保持應用程序設置類中的應用程序啓動計數。

用於存儲任何類型的設置界面:

public interface ISettingService 
    { 
     void Save(); 
     void Save(string key, object value); 
     bool AddOrUpdateValue(string Key, object value); 
     bool IsExist(string key); 
     T Load<T>(string key); 
     T GetValueOrDefault<T>(string Key, T defaultValue); 
    } 

該評級服務類消耗上述接口存儲這樣的數量和設置:

public class RatingService 
    { 
     private const string IsAppRatedKeyName = "isApprated"; 
     private const string TabViewCountKeyName = "tabViewCount"; 

     private const bool IsAppratedDefault = false; 
     private const int TabViewCountDefault = 0; 
     private const int ShowRatingInEveryN = 7; 

     private readonly ISettingService _settingService; 

     [Dependency] 
     public RatingService(ISettingService settingService) 
     { 
      _settingService = settingService; 
     } 

     public void RateApp() 
     { 
      if (_settingService.AddOrUpdateValue(IsAppRatedKeyName, true)) 
       _settingService.Save(); 
     } 

     public bool IsNeedShowMessage() 
     { 
      return (_settingService.GetValueOrDefault(TabViewCountKeyName, TabViewCountDefault)%ShowRatingInEveryN) == 0; 
     } 

     public void IncreaseTabViewCount() 
     { 
      int tabCount = _settingService.GetValueOrDefault(TabViewCountKeyName, TabViewCountDefault); 

      if (_settingService.AddOrUpdateValue(TabViewCountKeyName, (tabCount + 1))) 
       _settingService.Save(); 
     } 

     public bool IsAppRated() 
     { 
      return _settingService.GetValueOrDefault(IsAppRatedKeyName, IsAppratedDefault); 
     } 
    } 

這是你將如何運行這樣功能,並提示用戶對項目中任何位置(主頁面或用戶啓動某些功能的其他頁面)進行評分(如果以前未評分):

private void RunRating() 
     { 
      if (!RatingService.IsAppRated() && RatingService.IsNeedShowMessage()) 
      { 
       MessageBoxResult result = MessageBox.Show("Review the app?", "Would you like to review this awesome app?", 
        MessageBoxButton.OKCancel); 
       //show message. 
       if (result == MessageBoxResult.OK) 
       { 
        RatingService.RateApp(); 
        new MarketplaceReviewTask().Show(); 
       } 
      } 
     } 
+0

謝謝,Rate My App組件實際上的設置是在5次和10次後提示。我現在已經開始工作了。 感謝您發佈此代碼的簡化版本,因爲它可以幫助我更好地瞭解如何在WP8中執行此操作的過程。但是,現在我仍然會使用諾基亞'評價我的應用'組件。 –

+0

您的歡迎。順便提一下,在提出這些問題的同時,我建議不要包含非常具體的框架/實現。相反,更像是以概念的方式來解決你的問題。如果你這樣做,這將有助於更多的人瞭解這個想法。如果你認爲這個答案滿足你的問題,你應該將其標記爲答案。 – halil

相關問題