我已经创建了一个带有应用内购买的应用程序,并使用 CurrentAppSimulator
对其进行了测试,并且工作正常,但是当我为应用程序创建包时,它失败了
这是我正在为其创建包的代码
public async System.Threading.Tasks.Task InAppInit()
{
var listing = await CurrentApp.LoadListingInformationAsync();
// Delux Unlock - Durable
var unlockFeatureDelux = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "deluxe" && p.Value.ProductType == ProductType.Durable);
isDeluxPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureDelux.Value.ProductId].IsActive;
deluxProductID = unlockFeatureDelux.Value.ProductId;
// Standard Unlock - Durable
var unlockFeatureStandard = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "standard" && p.Value.ProductType == ProductType.Durable);
isStarndardPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureStandard.Value.ProductId].IsActive;
standardProductID = unlockFeatureStandard.Value.ProductId;
}
我在App.xaml.cs
中调用此方法OnLaunched
最佳答案
根据我们的讨论,我会这样做:
LoadListingInformationAsync
方法使用互联网,如果用户没有互联网连接,则会引发异常。所以我建议将这整个内容包装到 try/ctach block 中- 正如我们所见,
ProductListings
不包含任何项目。我不知道这个列表是如何填充的,但只要你的应用程序不在商店中,当该列表为空时我就不会感到惊讶(也许有人可以在这里提供帮助......但我没有找到任何与此相关的内容在文档中)。因此,为此,我只需检查您需要的功能是否在列表中...这样您的包将通过您提到的测试,您可以上传它。如果通过商店安装软件包时列表也是空的,则 IAP 设置有问题(但这与商店有关..) - 一般性评论:显然此代码并不完整...您需要一些代码来购买 IAP,而这里我们只能获取 Id..(但我认为您只是粘贴了相关部分。)
所有这些都在代码中:
public async System.Threading.Tasks.Task InAppInit()
{
try
{
var listing = await CurrentApp.LoadListingInformationAsync();
if (listing.ProductListings.ContainsKey("deluxe"))
{
// Delux Unlock - Durable
var unlockFeatureDelux = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "deluxe" && p.Value.ProductType == ProductType.Durable);
isDeluxPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureDelux.Value.ProductId].IsActive;
deluxProductID = unlockFeatureDelux.Value.ProductId;
}
else
{
//There is no deluxe IAP defined... so something with your IAP stuff is wrong...
}
if (listing.ProductListings.ContainsKey("standard"))
{
// Standard Unlock - Durable
var unlockFeatureStandard = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "standard" && p.Value.ProductType == ProductType.Durable);
isStarndardPurchased = CurrentApp.LicenseInformation.ProductLicenses[unlockFeatureStandard.Value.ProductId].IsActive;
standardProductID = unlockFeatureStandard.Value.ProductId;
}
else
{
//same as for Delux
}
}
catch
{
//Show this on the UI...
}
}
关于c# - Windows 应用商店应用中的应用内购买问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34083630/