locked
Store License Check

    Question

  • Just a quick question:

    If I offer my app as a FREE version by default with the option to upgrade it's built-in features via the BUY APP in the store, will this code suffice for checking current app status?

     

    (function () {
        appistrial = true;
        currentApp = Windows.ApplicationModel.Store.CurrentApp;
    
        licenseInformation = currentApp.licenseInformation;
    
        currentApp.licenseInformation.addEventListener("licensechanged", reloadLicense);
        reloadLicense();
    
    })();
    
    function reloadLicense() {
        if (licenseInformation.isActive) {
            if (licenseInformation.isTrial) { appistrial = true; }
            else { appistrial = false; }
        }
    }

    Then in my code, I can simply check to see if my variable "appistrial" is true or not. This would be easy enough, just want to make sure.

    Thanks...

    Friday, December 14, 2012 4:35 PM

Answers

  • As tt92618 suggested, you should make sure the app license checking c ode will execute no matter the app is newly launched or resume from a previous suspension. There are various places you can consider for adding such code.

    * The "activated" event is a one place which is fired whenever your app is launched:

    #How to handle app activation (Windows Store apps using JavaScript and HTML) (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465102.aspx

    * Of if your app will always display a default home page (through the navigation framework) first, you can also add the checking code in the "ready" event of the home page


    BTW, if your app use "in-app purchase" features, you need further code to check individual in-app purchase items separately. You can refer to the following SDK sample for detailed code logic:

    http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Thursday, December 20, 2012 10:28 AM
    Monday, December 17, 2012 5:40 AM
    Moderator
  • In general, yes, if you are checking on both a resume and an init you should be fine.

    When I look at the code you presented, however, i'm not certain it would work at all.

    I cannot tell from your code if you have defined the variable 'licenseInformation' anywhere, so I can only go by what I see here.  What I see in the code that you provided is this:  you declare licenseInformation and set it to currentApp.licenseInformation inside an anonymous function.  In doing that, you limit the scope of that variable to within that function.  This creates a problem because you then attempt to consume the resulting object from within the scope of the function 'reloadLicense', which is declared in a different scope.  Because of the different scoping of these functions, your reloadLicense function should never be able to obtain any licenseInformation at all; it should return undefined.

    That's a problem because of how you structured your evaluation inside reloadLicense.  That function checks licenseInformation.isActive, which will likely evaluate to false always, because licenseInformation will be undefined.  

    The same issues hold for your appIsTrial var, as well.  Scoping as you have, anything inside your anonymous function should not be accessible to functions declared outside it's scope.

    FYI, I just noticed that in your original post you were in fact calling reloadLicense directly, which probably would have worked if not for these scoping issues.

    • Proposed as answer by tt92618 Tuesday, December 18, 2012 3:29 PM
    • Marked as answer by Song Tian Thursday, December 20, 2012 10:27 AM
    Tuesday, December 18, 2012 5:51 AM

All replies

  • No it wont, because your function to check and set your internal variable is only fired when the license state for the app changes.  So, it would fire when the user upgrades, for instance, but never after that.  If the user were to interrupt app state, as in a restart, the app will then again be in trial mode because that is the initialized state of your app.

    You need also to check license state when the app initializes or comes back from a suspend.

    Monday, December 17, 2012 12:44 AM
  • As tt92618 suggested, you should make sure the app license checking c ode will execute no matter the app is newly launched or resume from a previous suspension. There are various places you can consider for adding such code.

    * The "activated" event is a one place which is fired whenever your app is launched:

    #How to handle app activation (Windows Store apps using JavaScript and HTML) (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/hh465102.aspx

    * Of if your app will always display a default home page (through the navigation framework) first, you can also add the checking code in the "ready" event of the home page


    BTW, if your app use "in-app purchase" features, you need further code to check individual in-app purchase items separately. You can refer to the following SDK sample for detailed code logic:

    http://code.msdn.microsoft.com/windowsapps/Licensing-API-Sample-19712f1a


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Thursday, December 20, 2012 10:28 AM
    Monday, December 17, 2012 5:40 AM
    Moderator
  • Thanks guys!

    So if I had the trigger check from a relaunch or suspend mode, would this work?

    I have no "in-app" purchases. My only concern is that the license checks the store when triggered, so if the client has no internet, would that prevent them from using the app even though they have previously purchased it?

    Monday, December 17, 2012 4:41 PM
  • In general, yes, if you are checking on both a resume and an init you should be fine.

    When I look at the code you presented, however, i'm not certain it would work at all.

    I cannot tell from your code if you have defined the variable 'licenseInformation' anywhere, so I can only go by what I see here.  What I see in the code that you provided is this:  you declare licenseInformation and set it to currentApp.licenseInformation inside an anonymous function.  In doing that, you limit the scope of that variable to within that function.  This creates a problem because you then attempt to consume the resulting object from within the scope of the function 'reloadLicense', which is declared in a different scope.  Because of the different scoping of these functions, your reloadLicense function should never be able to obtain any licenseInformation at all; it should return undefined.

    That's a problem because of how you structured your evaluation inside reloadLicense.  That function checks licenseInformation.isActive, which will likely evaluate to false always, because licenseInformation will be undefined.  

    The same issues hold for your appIsTrial var, as well.  Scoping as you have, anything inside your anonymous function should not be accessible to functions declared outside it's scope.

    FYI, I just noticed that in your original post you were in fact calling reloadLicense directly, which probably would have worked if not for these scoping issues.

    • Proposed as answer by tt92618 Tuesday, December 18, 2012 3:29 PM
    • Marked as answer by Song Tian Thursday, December 20, 2012 10:27 AM
    Tuesday, December 18, 2012 5:51 AM