2013-10-22 104 views
0

我最近發佈了一個小應用程序,其中有一個試用Windows Phone Marketplace,但我的應用程序無法按預期工作。在進行試用期間,我遵循http://code.msdn.microsoft.com/Trial-Experience-Sample-c58f21af,以便我可以調用當前的「LicenseInformation」狀態並根據當前應用程序的許可證狀態阻止某個功能。根據示例應用程序,The LicenseMode property returns a value from the LicenseModes enum (Full, MissingOrRevoked, or Trial) so that your app code needs to check only a single value. There’s also a convenient Boolean IsFull property. Whenever the license mode has changed, or it is likely to have changed, TrialExperienceHelper raises its LicenseChanged event and your app code can handle that event to query LicenseMode or IsFull again. Then, your app can control the availability of features, ads, and your Buy UI as needed.爲什麼我的應用程序試用版不能在市場上工作

在我的應用程序中,我有一個點擊事件,我想根據當前LicenseInformation狀態執行一個操作,並根據計數(計數是圖像保存的次數並適用特定方面)。

Settings.SavedCount.Value記錄點擊保存按鈕的次數,如果計數超過100並且應用程序處於試用模式,我想詢問用戶是否想要升級,否則如果計數較少當應用程序處於試用模式時,或者許可證處於完全模式時,允許用戶繼續保存過程(希望這符合邏輯)。

void saveButton_Click(object sender, EventArgs e) 
{ 
    Settings.SavedCount.Value += 1;   

    if (TrialViewModel.LicenseModeString == "Trial" && Settings.SavedCount.Value > 100) 
    { 
     MessageBoxResult result = MessageBox.Show("You have saved over 100 items! Would you like to continue?", "Congratulations!", MeesageBoxButton.OKCancel); 

     switch (result) 
     { 
      case MessageBoxResult.OK: 
       //A command takes a parameter so pass null 
       TrialViewModel.BuyCommand.Execute(null); 
       break; 
      case MessageBoxResult.Cancel: 
       editPagePivotControl.SelectedIndex = 0; 
       break;     
     } 
    } 
    else if ((TrialViewModel.LicenseModeString == "Trial" && Settings.SavedCount.Value <= 100) || (TrialViewModel.LicenseModeString == "Full") 
     { 
      PerformSaveAsync(); 
     } 
    } 
} 

在調試模式下,用從MSDN網站上的樣品執行測試,試用和完全實現工作正常,然後當在Release模式牌照被列爲MissingOrRevoked我認爲會被正確地在叫市場。當我在市場中以試用模式和完整模式下載應用程序時,實際發生的事情是0123'方法永遠不會被調用(最終保存新圖像並禁用按鈕),我可以在其他地方使用新圖像。我無法弄清楚問題可能是什麼?

編輯**在研究中,我碰到了http://msdn.microsoft.com/en-us/library/aa691310(v=vs.71).aspx其中指出The operation x && y corresponds to the operation x & y, except that y is evaluated only if x is true.和`•操作x || y對應於操作x | y,除了y只在x爲假/'時才被評估。這會成爲問題的原因嗎?如果是這樣,他們應該如何修復?

編輯2 **,瞭解更多信息TrialViewModel和TrialExperienceHelper.cs的Addtion

TrialViewModel

TrialViewModel 

#region fields 
private RelayCommand buyCommand; 
#endregion fields 

#region constructors 
public TrialViewModel() 
{ 
    // Subscribe to the helper class's static LicenseChanged event so that we can re-query its LicenseMode property when it changes. 
    TrialExperienceHelper.LicenseChanged += TrialExperienceHelper_LicenseChanged; 
} 
#endregion constructors 

#region properties   
/// <summary> 
/// You can bind the Command property of a Button to BuyCommand. When the Button is clicked, BuyCommand will be 
/// invoked. The Button will be enabled as long as BuyCommand can execute. 
/// </summary> 
public RelayCommand BuyCommand 
{ 
    get 
    { 
     if (this.buyCommand == null) 
     { 
      // The RelayCommand is constructed with two parameters - the action to perform on invocation, 
      // and the condition under which the command can execute. It's important to call RaiseCanExecuteChanged 
      // on a command whenever its can-execute condition might have changed. Here, we do that in the TrialExperienceHelper_LicenseChanged 
      // event handler. 
      this.buyCommand = new RelayCommand(
       param => TrialExperienceHelper.Buy(), 
       param => TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.Trial); 
     } 
     return this.buyCommand; 
    } 
} 

public string LicenseModeString 
{ 
    get 
    { 
     return TrialExperienceHelper.LicenseMode.ToString()/* + ' ' + AppResources.ModeString*/; 
    } 
} 
#endregion properties 

#region event handlers 
// Handle TrialExperienceHelper's LicenseChanged event by raising property changed notifications on the 
// properties and commands that 
internal void TrialExperienceHelper_LicenseChanged() 
{ 
    this.RaisePropertyChanged("LicenseModeString"); 
    this.BuyCommand.RaiseCanExecuteChanged(); 
} 
#endregion event handlers 

TrialExperienceHelper.cs

#region enums 
    /// <summary> 
    /// The LicenseModes enumeration describes the mode of a license. 
    /// </summary> 
    public enum LicenseModes 
    { 
     Full, 
     MissingOrRevoked, 
     Trial 
    } 
    #endregion enums 

    #region fields 
#if DEBUG 
    // Determines how a debug build behaves on launch. This field is set to LicenseModes.Full after simulating a purchase. 
    // Calling the Buy method (or navigating away from the app and back) will simulate a purchase. 
    internal static LicenseModes simulatedLicMode = LicenseModes.Trial; 
#endif // DEBUG 
    private static bool isActiveCache; 
    private static bool isTrialCache; 
    #endregion fields 

    #region constructors 
    // The static constructor effectively initializes the cache of the state of the license when the app is launched. It also attaches 
    // a handler so that we can refresh the cache whenever the license has (potentially) changed. 
    static TrialExperienceHelper() 
    { 
     TrialExperienceHelper.RefreshCache(); 
     PhoneApplicationService.Current.Activated += (object sender, ActivatedEventArgs e) => TrialExperienceHelper. 
#if DEBUG 
      // In debug configuration, when the user returns to the application we will simulate a purchase. 
OnSimulatedPurchase(); 
#else // DEBUG 
      // In release configuration, when the user returns to the application we will refresh the cache. 
RefreshCache(); 
#endif // DEBUG 
    } 
    #endregion constructors 

    #region properties 
    /// <summary> 
    /// The LicenseMode property combines the active and trial states of the license into a single 
    /// enumerated value. In debug configuration, the simulated value is returned. In release configuration, 
    /// if the license is active then it is either trial or full. If the license is not active then 
    /// it is either missing or revoked. 
    /// </summary> 
    public static LicenseModes LicenseMode 
    { 
     get 
     { 
#if DEBUG 
      return simulatedLicMode; 
#else // DEBUG 
      if (TrialExperienceHelper.isActiveCache) 
      { 
       return TrialExperienceHelper.isTrialCache ? LicenseModes.Trial : LicenseModes.Full; 
      } 
      else // License is inactive. 
      { 
       return LicenseModes.MissingOrRevoked; 
      } 
#endif // DEBUG 
     } 
    } 

    /// <summary> 
    /// The IsFull property provides a convenient way of checking whether the license is full or not. 
    /// </summary> 
    public static bool IsFull 
    { 
     get 
     { 
      return (TrialExperienceHelper.LicenseMode == LicenseModes.Full); 
     } 
    } 
    #endregion properties 

    #region methods 
    /// <summary> 
    /// The Buy method can be called when the license state is trial. the user is given the opportunity 
    /// to buy the app after which, in all configurations, the Activated event is raised, which we handle. 
    /// </summary> 
    public static void Buy() 
    { 
     MarketplaceDetailTask marketplaceDetailTask = new MarketplaceDetailTask(); 
     marketplaceDetailTask.ContentType = MarketplaceContentType.Applications; 
     marketplaceDetailTask.Show(); 
    } 

    /// <summary> 
    /// This method can be called at any time to refresh the values stored in the cache. We re-query the application object 
    /// for the current state of the license and cache the fresh values. We also raise the LicenseChanged event. 
    /// </summary> 
    public static void RefreshCache() 
    { 
     TrialExperienceHelper.isActiveCache = CurrentApp.LicenseInformation.IsActive; 
     TrialExperienceHelper.isTrialCache = CurrentApp.LicenseInformation.IsTrial; 
     TrialExperienceHelper.RaiseLicenseChanged(); 
    } 

    private static void RaiseLicenseChanged() 
    { 
     if (TrialExperienceHelper.LicenseChanged != null) 
     { 
      TrialExperienceHelper.LicenseChanged(); 
     } 
    } 

#if DEBUG 
    private static void OnSimulatedPurchase() 
    { 
     TrialExperienceHelper.simulatedLicMode = LicenseModes.Full; 
     TrialExperienceHelper.RaiseLicenseChanged(); 
    } 
#endif // DEBUG 
    #endregion methods 

    #region events 
    /// <summary> 
    /// The static LicenseChanged event is raised whenever the value of the LicenseMode property has (potentially) changed. 
    /// </summary> 
    public static event LicenseChangedEventHandler LicenseChanged; 
    #endregion events 

回答

0

如果你的開發建立的工作,唯一不同的是隨着應用程序通過商店發佈,那麼我認爲這不太可能成爲你的邏輯。

當您提交應用程序時,您確定已選中了可以在應用程序中使用試用功能的選項嗎?

free trial option partial screenshot

如果沒有檢查這個那麼就不會在發佈的應用程序工作。

+0

是的,我相信我是這麼做的,因爲在商店中提供了試用或購買版本(雖然我在發現這些錯誤時從商店中未發佈應用程序,所以沒有人會經歷相同的情況)。 – Matthew

+0

你是否認爲它可能是條件運算符不在'if else'中執行兩個條件語句?閱讀http://msdn.microsoft.com/en-us/library/aa691310(v=vs.71).aspx讓我三思,是否應該使用邏輯或條件運算符。另外,我正在考慮執行不同的字符串比較方法,並在此處發佈了一個問題http://stackoverflow.com/questions/19530857/trouble-with-logical-and-conditional-operators/19538644?noredirect=1#19538644。你怎麼看? – Matthew

+0

好吧,我似乎別無選擇,只能嘗試和更新市場上的應用程序。我做了檢查,我確實有試用選項,並在所有市場中以基本價格層級(.99美元)提供應用程序。如果不是這樣,我將改變if語句中檢查項目的順序,以及可能使用邏輯運算符而不是條件。如果不是這樣,那麼我不確定是什麼,可能會回到WP7檢查試用許可證的方式。 – Matthew

0

關於你的編輯,我看不出有什麼問題,你的條件,你的報價僅僅是運營商很懶,只需要什麼來確定結果(例如,在計算時,你做X & &ÿ如果x is false,x & & false => false和x & & true == false這是相同的結果,因此它不評估y)。
也就像我在你之前的問題中所說的,即使windows phone 7 api仍然可以在windows phone 8上運行,所以如果你爲這兩個平臺創建代碼,那麼可能不需要專門爲wp8使用新的api。
在這段代碼中,我沒有看到任何問題,但爲什麼要將LicenseModes枚舉轉換爲字符串,使用枚舉將添加一些類型的安全性,並防止您做一些無效的比較。
唯一的問題是您在PerformSaveAsync中設置LicenseModeString或問題的位置?

+0

我必須誤解我自己關於LicenseModes枚舉,它是'public enum LicenseModes { Full, MissingOrRevoked, Trial }''。我相信我會在檢查'TrialViewModel.LicenseModeString'之前更改我的條件順序來檢查'Settings.SavedCount.Value'。我也應該改爲邏輯而不是條件運算符來檢查整個if else語句嗎?並且'PerformSaveAsync'還沒有被調用,因爲它更新了視圖並禁用了一個按鈕,所以我會看到這種改變。 – Matthew

+0

另外,我將更新我的解決方案,以比較TrialViewModel.LicenseModeString與其Trial或Full的狀態,使用另一個字符串比較版本,如http://msdn.microsoft.com/en-us/library/vstudio/ cc165449(v = vs.110).aspx這可能有幫助嗎?在這一點上,我會嘗試任何事情。 – Matthew

+0

@Matthew就像我在我的回覆中所說的,我不認爲改變順序會改變任何事情,不管順序如何,響應仍然是一樣的,只是有些部分不會被評估以節省一些時間(你想要什麼) 。你唯一需要確定的是你在正確的地方有括號,這在你粘貼的代碼中看起來很好(即使在第二個時候,如果最後缺少括號但我想它只是一個錯誤的複製粘貼。另外,我仍然不明白爲什麼你不保留LicenseView中的LicenseMode枚舉值,而不是字符串... –

相關問題