[英]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.