购买模拟对话框未显示 (CurrentAppSimulator.RequestProductPurchaseAsync)

Purchase simulation dialog does not show up (CurrentAppSimulator.RequestProductPurchaseAsync)

我正在为 Windows 8 开发应用程序。一段时间后,我将项目更新为 Windows 8.1,我收到警告,方法 CurrentAppSimulator.RequestProductPurchaseAsync(字符串,布尔值) 来自 CurrentAppSimulator class is deprecated. So I started using CurrentAppSimulator.RequestProductPurchaseAsync(String) version of it, and for some reason the purchase simulation dialog does not show up at all. Here is a dialog I was getting using deprecated version of the method.

我以前从来不需要 WindowsStoreProxy.xml,但以防万一我检查了它并设置了 IsTrial 属性 到 false - 但是,对话框不会显示,and 新方法的答案 CurrentAppSimulator.RequestProductPurchaseAsync(String) 总是returns ProductPurchaseStatus::NotPurchased.

也许有人知道问题出在哪里?

返回NotPurchased,因为WindowsStoreProxy.xmlCurrentAppSimulator[=使用的文件WindowsStoreProxy.xml 39=] 不包含请求的产品。您需要填写 WindowsStoreProxy.xml 您提供给应用程序用户的所有产品。 Here are some examples, written by Microsoft.

WindowsStoreProxy.xml 是在此位置首次启动应用程序时创建的:

C:\Users\<username>\AppData\Local\Packages\<app package folder>\LocalState\Microsoft\Windows Store\ApiData\WindowsStoreProxy.xml

此外,在每次 CurrentAppSimulator.RequestProductPurchaseAsync(String) 调用后,当结果为 ProductPurchaseStatus.Succeeded 时,您需要做两件事:

  1. 授予用户产品(例如购买的商品)
  2. 通知商店,产品履行已成功完成 - 使用方法 CurrentApp.ReportConsumableFulfillmentAsync(String, Guid)。确保之后返回的 FulfillmentResultFulfillmentResult::Succeeded

完成这些步骤后,您的商品应该已成功购买并发货。

查看详细解释:Enable consumable in-app product purchases.

如果您需要进一步了解每个 FulfillmentResult 对购买的意义,您可以在 Adam Nathan 的 "Universal Windows Apps with XAML and C# Unleashed" 一书中查找非常好的解释,我在谷歌搜索这些东西时发现的。