Search Unity

Windows store trial licencing

Discussion in 'Windows' started by Brickit, Nov 18, 2013.

  1. Brickit

    Brickit

    Joined:
    Jul 4, 2012
    Posts:
    30
    Hi,

    We need to be able to get this http://msdn.microsoft.com/en-us/library/windows/apps/hh694065.aspx into our Unity project.

    Is it possible to do it from the Unity side via plugins (as opposed to bolting stuff on to the VS C++ project it spits out)

    -Or if someone knows of a plugin that can handle this we would be grateful.
    -Or a good tutorial on writing store plugins when using C++ output.
     
    Last edited: Nov 18, 2013
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  3. Brickit

    Brickit

    Joined:
    Jul 4, 2012
    Posts:
    30
    Oh thank you!, that's great! :)
    Saved me some hacking anyway.
     
  4. Brickit

    Brickit

    Joined:
    Jul 4, 2012
    Posts:
    30
    I'm not sure this is complete because it should have a "licenseInformation.expirationDate" getter as well.
    I can only see this as a way of disabling parts of the app, however we want a limited trial with full functionality. We could always write our own time check, but how would we save this in such a way that when the app is removed-reinstalled it is not cleared?
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    You're right, it is missing that on Windows Store Apps. However, there are a few reasons why this is the case:

    1. That API (to check for expiration) is only available on Windows Store Apps, whereas on Windows Phone, you have to track it yourself (refer to http://stackoverflow.com/questions/19656893/windows-phone-8-trial-expiration-time). With this API we wanted to make it a consistent experience between Windows Store Apps and Windows Phone.

    2. If you REALLY need access to that property on Windows Store Apps project, wrap your code #if NETFX_CORE/#endif and then just use Windows API:
    Code (csharp):
    1.  
    2. #if NETFX_CORE
    3. <your code for Windows Store Apps>
    4. #endif
    5.  
    Note: this won't work on anything else other than Windows Store Apps.
     
    Last edited: Nov 25, 2013
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,919
    It's NETFX_CORE, not NET_FX :)
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Oops! Thanks, corrected :).
     
  8. Brickit

    Brickit

    Joined:
    Jul 4, 2012
    Posts:
    30
    I have now written a time check which works with a test variable but how do i actually set the application to a trial?
    Windows.LicenseInformation.isOnAppTrial seems to return false always.

    Code (csharp):
    1.                 bool debugNoReg = false;
    2.                 if (LicenseInformation.isOnAppTrial | debugNoReg) {
    3.                     Debug.Log("Is trial version");
    4.                     System.TimeSpan remainingTime = RemainingTrialTime ();
    5.                     if(remainingTime.TotalHours<0){
    6.                         Debug.Log("Trial expired");
    7.                         Application.LoadLevel("TrialExpired");
    8.                     }
    9.                 } else {
    10.                     Debug.Log("Is full version");
    11.                     //Do nothing ?
    12.                 }
    this is the other code i got that is supposed to handle the store bit in my TrialExpired scene :

    Code (csharp):
    1.         if(closeButton.isHit){
    2.             Application.Quit();
    3.  
    4.         }
    5.  
    6.         if(m_Receipt!=null  m_Receipt.Length>0){
    7.             Application.LoadLevel("Title");
    8.  
    9.         }else{
    10.             if (mainOkButton.GetComponent<ClickableValue>().isReleasedAndStillOver){
    11.                 #if UNITY_METRO
    12.                 m_Receipt = LicenseInformation.PurchaseApp ();
    13.                 #endif
    14.             }
    15.         }
    However I am confused about this, if i override the is AppOnTrial with my debugNoReg boolean and run this as a package, I get a store box pop up with a simulated purchase which says return the strings:

    S_OK
    E_INVALIDREG
    E_FAIL
    E_OUTOFMEMORY

    However the Unity docs just says "returns a valid purchase reciept or empty if not purchased", and does not say anywhere about what to do with that reciept string, or how to then set the app to know it is "registered".
     
    Last edited: Nov 29, 2013
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  10. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
  11. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    LicenseInformation does not exists anymore on Unity Documentation.

    http://docs.unity3d.com/Documentation/ScriptReference/Windows.LicenseInformation-isOnAppTrial.html
    http://docs.unity3d.com/Documentation/ScriptReference/Windows.LicenseInformation.PurchaseApp.html

    All invalid links now!

    I still have problems detecting if my application is on Trial Mode or Not (it always return isOnAppTrial==false).

    The ES version is still online
    http://docs.unity3d.com/es/current/ScriptReference/Windows.LicenseInformation.html

    Please, anybody was able to make it work with Unity 5? Any official word on this, why it was removed from documentation? It does not works anymore? What should I use?
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    How are you testing it? Which platform is this on?

    Sorry about the documentation - looks like a documentation bug on our side.
     
  13. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
  15. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    There is a problem with Prime31 Windows Store Plugiun, but with the Native Unity it worked now!

    Thanks for the Support...
     
  16. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    354
    Can I check with this that LicenseInformation.isOnAppTrial and LicenseInformation.PurchaseApp() both work on Windows Phone? I've just been bitten by WinBridge being Windows Store only and not communicating that very well, and whenever I read about LicenseInformation (bearing in mind the documentation is still down) I see phrases like "only works for Windows Store" that destroy my confidence that this is actually the solution for WP8. I could do with a solid yes or no, thanks
     
  17. PrettyFlyGames

    PrettyFlyGames

    Joined:
    Aug 30, 2012
    Posts:
    74
    This function seems to crash when called from a IL2CPP UWP project. Is this supported still and is there anything special you need to do to use it?

    Crash exception:
    Unhandled exception at 0x00007FFFC627AE9C (GameAssembly.dll)
     
    Last edited: Aug 8, 2019
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    It should definitely work. Can we get a bug report on it?

    In the mean time, you could work around by calling the Windows API directly from your script:

    Code (csharp):
    1. static bool IsOnAppTrial()
    2. {
    3. #if ENABLE_WINMD_SUPPORT && UNITY_WSA
    4.     return Windows.ApplicationModel.Store.CurrentApp.LicenseInformation.IsTrial;
    5. #else
    6.     return false;
    7. #endif
    8. }
     
  19. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    I added:
    using Windows.ApplicationModel.Store;

    But it says "the type or namespace 'Windows' could not be found", how do I add it?
     
  20. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Wrap it in "#if ENABLE_WINMD_SUPPORT && UNITY_WSA"/"#endif"
     
  21. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    Thanks I added the following and did a build:

    Code (CSharp):
    1. #if ENABLE_WINMD_SUPPORT && UNITY_WSA
    2.   using Windows.ApplicationModel;
    3.   using Windows.ApplicationModel.Store;
    4. #endif
    5.  
    6.   public bool IsTrialVersion()
    7.   {
    8. #if ENABLE_WINMD_SUPPORT && UNITY_WSA
    9.     return Windows.ApplicationModel.Store.CurrentAppSimulator.LicenseInformation.IsTrial;
    10. #else
    11.     return false;
    12. #endif
    13.   }
    But it now throws this error:

    BuildFailedException: Burst compiler (1.2.0-preview.9) failed running
    stdout:
    An unexpected exception occurred:
    stderr:
    Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null'
    at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    at Burst.Compiler.IL.AssemblyLoader.Resolve(AssemblyNameReference name)
    at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    at Mono.Cecil.TypeReference.Resolve()
    at Burst.Compiler.IL.Helpers.CecilExtensions.StrictResolve(TypeReference typeReference)
    at Burst.Bcl.BclApp.FindExecuteMethods(List`1 rootAssemblyPaths)
    at Burst.Bcl.BclApp.GetMethodsToCompileBeforeDynamicDispatch()
    at Burst.Bcl.BclApp.GetMethodsToCompile()
    at Burst.Bcl.Program.Main(String[] args)


    Running Unity 2019.2.10f1
     
  22. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    Disabling the Burst compiler fixed that issue. Will notify them.
     
  23. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I believe this is a known issue in burst that is being fixed.

    EDIT: this is fixed in Unity 2019.3 which should be out very soon.
     
    Last edited: Nov 6, 2019