简体   繁体   English

在应用程序购买过期后,在应用程序的许可证信息的AddOnLicenses属性中没有记录

[英]In app purchases after they've expired don't have a record in the app's license info's AddOnLicenses property

I'm having a problem with my durable in-app-purchases. 我的耐用应用内购买存在问题。 For testing purposes, I have set the premium trial IAP for my app to expire after a day. 出于测试目的,我已将我的应用的高级试用版IAP设置为在一天后过期。 I copied the following code from https://msdn.microsoft.com/en-gb/windows/uwp/monetize/get-license-info-for-apps-and-add-ons to obtain the app's license info: 我从https://msdn.microsoft.com/en-gb/windows/uwp/monetize/get-license-info-for-apps-and-add-ons复制了以下代码,以获取应用程序的许可证信息:

    private StoreContext context = null;
    private async Task<bool> getLicenseInfo()
    {
        try
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            // license wasn't retrieved, for example because user is offline, so..
            // need to fallback on non-premium version
            if (appLicense == null)
            {
                return false;
            }

            // iterate through the add on licenses for add-ons for this app.
            foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;
                if (addOnLicense.InAppOfferToken.Equals("test1_premium"))
                    Windows.Storage.ApplicationData.Current.RoamingSettings.Values["PremiumPurchased"] = addOnLicense.IsActive;
                else if (addOnLicense.InAppOfferToken.Equals("test1_premiumTrial"))
                    Windows.Storage.ApplicationData.Current.RoamingSettings.Values["PremiumTrialActive"] = addOnLicense.IsActive;
            }

            return true;
        }
        catch( Exception e )
        {
            return false;
        }
    }

During the 24 hours after the premium trial IAP was purchased, the premium trial IAP is returned in appLicense.AddOnLicenses, and is correctly set to active with the correct expiration time. 在购买高级试用版IAP后的24小时内,高级试用版IAP将在appLicense.AddOnLicenses中返回,并在正确的到期时间内正确设置为活动状态。 However, after approximately a day (I'm not 100%), appLicense.AddOnLicenses no longer contains a record for the IAP (and so the loop isn't entered resulting in the value of the RoamingSetting to indicate the active status of the IAP not being updated to reflect that it may have expired ie false). 但是,大约一天后(我不是100%),appLicense.AddOnLicenses不再包含IAP记录(因此未输入循环,导致RoamingSetting的值表示IAP的活动状态没有更新,以反映它可能已过期,即错误)。

The fact IAPs have an isActive property to me suggests that IAPs even after they've expired should still retain a record in appLicense.AddOnLicenses, albeit with isActive set to false. 事实上IAP对我有一个isActive属性表明IAP即使在它们过期之后仍然应该在appLicense.AddOnLicenses中保留一条记录,尽管isActive设置为false。 What I'm seeing however may suggest otherwise. 然而,我所看到的可能会暗示其他情况。 Can someone please provide any clarification on this? 有人可以就此提供任何澄清吗? If it's confirmed that an expired IAP does have its record removed, then it will be straightforward - just set the IAP's RoamingSetting to false if no record was found. 如果确认过期的IAP确实删除了其记录,那么它将是直截了当的 - 如果没有找到记录,只需将IAP的RoamingSetting设置为false。 However, I've a feeling something else is going on here which may require a different solution. 但是,我有一种感觉,这里可能需要一个不同的解决方案。

I can confirm that the expired IAP will have its record removed in my app, in this way we need to do some records as you said using the RoamingSetting to check if the IAP is expired or not. 我可以确认过期的IAP会在我的应用程序中删除其记录,这样我们就需要做一些记录,就像你说使用RoamingSetting来检查IAP是否过期。

Besides, I will consult the related team to see if it is a expected behavior. 此外,我会咨询相关团队,看看它是否是预期的行为。

Another workaround is to implement the IAP using the Windows.ApplicationModel.Store namespace and we can use the following method to check the IAP's expiration date: 另一种解决方法是使用Windows.ApplicationModel.Store命名空间实现IAP,我们可以使用以下方法检查IAP的到期日期:

LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
if(licenseInformation.ProductLicenses[productId].IsActive)
  {
     var productLicense1 = licenseInformation.ProductLicenses[productId];
     var longdateTemplate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longdate");
     MyExpireDataTextBlock.Text = "ExpirationDate" + longdateTemplate.Format(productLicense1.ExpirationDate) + ". remain days: " + (productLicense1.ExpirationDate - DateTime.Now).Days;

   }
 else
   {

   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用内购买不会在应用安装之间持续存在 - In-App Purchases don't persist between app installations 验证应用内购买 - Verifying in-app purchases 证书过期后Windows应用程序将正常工作吗 - Will the windows app work after the certificate is expired 在Windows Store App(8 Metro)中将事件分配给Usercontrol的属性 - assign an event to a Usercontrol's property in Windows Store App ( 8 Metro ) 在Windows应用商店中无法绑定到Frame的SourcePageType - Binding to Frame's SourcePageType doesn't work in Windows store App 通用Windows应用程序如何具有多个独立窗口(如Microsoft的应用程序“照片”)? - How can a universal windows app have multiple independent windows (Like Microsoft's app “Photos”)? 如何获取Windows应用商店应用的标题和版本信息? - How can I get my Windows Store app's title and version info? 如何使Metro应用内购买有效? - How to get Metro in-app purchases to work? 在提交应用程序时,我应在哪里声明应用程序内购买? - When submitting the app where do I declare the In-App Purchases? 由于其许可证存在问题,此应用程序无法启动 - This app failed to launch because of an issue with its license
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM