windows 商店应用中的应用内购买问题
in app purchase issue in windows store app
我已经使用应用内购买创建了一个应用并使用 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 块
- 我们看到
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...
}
}
我已经使用应用内购买创建了一个应用并使用 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 块- 我们看到
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...
}
}