【发布时间】:2015-08-31 09:30:35
【问题描述】:
我想在我的 Windows 通用应用中集成应用内购买。我在编码之前做了以下事情。
在Windows Dev Center上制作应用
在 IAP 部分添加带有详细信息的产品并提交到商店,如您在 Image 中看到的那样
- 之后,我在我的应用中使用以下代码来获取应用内购买的产品列表和购买产品的按钮。我还在代码中使用了
CurrentApp而不是CurrentAppSimulator,但它出现了异常。
private async void RenderStoreItems()
{
picItems.Clear();
try
{
//StoreManager mySM = new StoreManager();
ListingInformation li = await CurrentAppSimulator.LoadListingInformationAsync();
System.Diagnostics.Debug.WriteLine(li);
foreach (string key in li.ProductListings.Keys)
{
ProductListing pListing = li.ProductListings[key];
System.Diagnostics.Debug.WriteLine(key);
string status = CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive ? "Purchased" : pListing.FormattedPrice;
string imageLink = string.Empty;
picItems.Add(
new ProductItem
{
imgLink = key.Equals("BaazarMagzine101") ? "block-ads.png" : "block-ads.png",
Name = pListing.Name,
Status = status,
key = key,
BuyNowButtonVisible = CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive ? false : true
}
);
}
pics.ItemsSource = picItems;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
}
}
private async void ButtonBuyNow_Clicked(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
string key = btn.Tag.ToString();
if (!CurrentAppSimulator.LicenseInformation.ProductLicenses[key].IsActive)
{
ListingInformation li = await CurrentAppSimulator.LoadListingInformationAsync();
string pID = li.ProductListings[key].ProductId;
string receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(pID, true);
System.Diagnostics.Debug.WriteLine(receipt);
// RenderStoreItems();
}
}
我还将我的应用与 Store 关联,并且我的应用包与 MS Dev Center 应用中的相同,如您在 Image 中看到的那样
当我运行我的应用并点击购买按钮时,我得到了这个对话框,正如你在Image 中看到的那样,之后我没有从商店获得收据数据。
如果我做错了,请给我适当的指导来实施应用内购买并在我的笔记本电脑设备上测试应用内购买。
【问题讨论】:
标签: c# .net windows-10 win-universal-app windows-rt