为什么我的应用程序试用版无法在市场中正常工作 [英] Why Could My Application Trial Not be Working in the Marketplace

查看:73
本文介绍了为什么我的应用程序试用版无法在市场中正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在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.

I recently have released a small application with a trial to the Windows Phone Marketplace, but my application is not working as expected. I have followed http://code.msdn.microsoft.com/Trial-Experience-Sample-c58f21af when making my trial, so that I can call the current 'LicenseInformation' state and block a feature or not depending on the current application's license state. According to the sample application, 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.

在我的应用程序中,我有一个click事件,在该事件中,我想根据当前的LicenseInformation状态和计数(计数是应用了特定方面保存图像的次数)执行操作.

In my application I have a click event in which I would like to perform an action based on the current LicenseInformation state and upon a count (the count being the number of times an image is saved with particular aspects applied).

Settings.SavedCount.Value记录单击保存按钮的次数,如果计数超过100并且应用程序处于试用模式,我想询问用户是否要升级,否则是否要计数在应用程序处于试用模式或许可证处于完全模式时,如果少于100,则允许用户继续保存过程(希望这是合乎逻辑的).

Settings.SavedCount.Value records the number of times the save button is clicked, and if the count is above 100 and the application is in trial mode I would like to ask the user if they would like to upgrade, otherwise if the count is less than 100 while the application is in trial mode or if the license is in full mode then the user is allowed to continue with the save process (hopefully that makes logical sense).

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();
        }
    }
}

当在Debug模式下进行测试并通过msdn网站上的示例实现进行测试时,Trial和Full实现可以正常工作,然后在Release模式下,该许可证被列为MissingOrRevoked,我认为在市场上该许可证会被正确调用.当我以试用和完整模式在市场上下载该应用程序时,实际上发生的事情是从未调用PerformSaveAsync()方法(这最终会保存新图像并禁用该按钮),并且我可以在其他地方使用该新图像.我在弄清楚问题可能出在什么地方?

When testing in Debug mode and with the sample implementation from the msdn website, the Trial and Full implementations worked properly, and then when in Release mode the license was listed as MissingOrRevoked which I assumed would be called correctly in the marketplace. What is ACTUALLY occuring when i have downloaded the app in the marketplace under both trial and full modes is that the PerformSaveAsync() method is never being called (which ultimately saves the new image and disables the button) and I can use the new image elsewhere. I am having trouble figuring out what the issue may be?

编辑**在研究中,我遇到了 http ://msdn.microsoft.com/zh-CN/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,只是仅当x为false/'时才对y求值.这是问题的原因吗?如果是这样,应该如何解决?

EDIT** In researching I came across http://msdn.microsoft.com/en-us/library/aa691310(v=vs.71).aspx which states that The operation x && y corresponds to the operation x & y, except that y is evaluated only if x is true. and `•The operation x || y corresponds to the operation x | y, except that y is evaluated only if x is false/' . Would this be the cause of the issues? If so, how should they be fixed?

编辑2 **添加TrialViewModel和TrialExperienceHelper.cs以获取更多信息

Edit 2** Addtion of TrialViewModel and TrialExperienceHelper.cs for additional info

TrialViewModel

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

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

推荐答案

关于您的编辑,我认为您的情况没有任何问题,您的报价只是操作员很懒,只评估确定所需的条件.结果(例如,如果x为假,则进行x& y,则x& false => false和x& true == false,这是相同的结果,因此不评估y).
就像我在上一个问题中所说的那样,即使Windows Phone 7 api仍然可以在Windows Phone 8上运行,因此,如果您要为两个平台都创建代码,则可能无需使用专门针对wp8的新api. 在这段代码中,我没有看到任何问题,但是为什么您将LicenseModes枚举转换为字符串,使用该枚举会增加某种类型的安全性并阻止您进行一些无效的比较.
唯一的问题是您在哪里设置LicenseModeString或PerformSaveAsync内部有问题?

Regarding your edit, I don't see any problem with your condition, your quote is just that the operator is lazy, evaluating only what is needed to determine the result (for example when you do x&& y if x is false, x&& false=> false and x&& true==false which is the same result so it don't evaluate y).
Also like I said in your previous question even the windows phone 7 api still work on windows phone 8 so if you are creating code for both platform there is probably no need to use the new api specifically for wp8.
In this code I don't see any problem but why do you convert the LicenseModes enum to string, using the enum will add some type safety and prevent you to do some invalid comparison.
The only problem is where you set LicenseModeString or a problem inside PerformSaveAsync?

这篇关于为什么我的应用程序试用版无法在市场中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆