locked
Trial experience of app is allowing unrestricted access

    Question

  • I launched my first app yesterday to the store. The app has a trial version which simply restricts full access to the game.

    I downloaded the trial and played for a while, no problems - good.

    I then purchased the full version by from the store and started the app again only to find that it didnt release it's restrited areas - NOT good.

    I have implemented the following code in the app to implement the restrictions:

    {
    	/// <summary>
    	/// The TrialExperienceHelper class can serve as a convenient building-block in your app's trial experience implementation. It queries
    	/// the license as infrequently as possible, and caches the results, for maximum performance. When built in debug configuration, the class simulates the purchase
    	/// experience when the Buy method is called. To customize what happens in debug when Buy is called, initialize the simulatedLicMode and/or
    	/// simulatedLicModeOnPurchase fields to different values. A release build of this class will have access to a license only when the app is
    	/// published to the Windows Phone Store. For a release build not published to the Store, the value of the LicenseMode property will be
    	/// LicenseModes.MissingOrRevoked.
    	/// </summary>
        public static class TrialExperienceHelper
        {
            #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
        }
    }

    Then in my code I'm using if's to determine what to allow with this:

    if ((TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.Trial)||
                    (TrialExperienceHelper.LicenseMode == TrialExperienceHelper.LicenseModes.MissingOrRevoked))
    {
              //Then display ads etc
    }

    This call must be returning TRUE...!

    I need to update the app ASAP but for the life of me I can't see the mistake, maybe someone here more experienced can help?

    What hve I done wrong here?






    Wednesday, July 30, 2014 1:47 PM

Answers

  • Hi Wired Voltage,

    You are debugging with the app? In the debug mode, TrialExperienceHelper.LicenseMode is set to Trail in your code and the condition always be true.

    And I would suggest you to use CurrentAppSimulator to test your code before submite to the store.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, July 31, 2014 8:25 AM
    Moderator