我已经使用 CurrentAppSimulator 设置了应用内购买,并设置了获取应用内购买的功能。我还(可能)配置了我的 WindowsStoreProxy.xml 文件来处理这个问题。
但是,当我购买插件并为其返回一个 S_OK
值时,它仍然表示 IAP 处于非事件状态。使它处于事件状态的唯一方法是手动编辑 WindowsStoreProxy.xml 文件并将 Active 属性设置为 Active。这看起来很奇怪,因为 Microsoft 的商店示例运行良好。不过,我看不出他们有什么不同——他们仍然使用 CurrentAppSimulator.RequestProductPurchaseAsync()
方法。我哪里出错了...?
最佳答案
首先,我使用自己的类 CurrentAppProxy,它在 Debug模式下使用 CurrentAppSimulator,在 Release模式下使用 CurrentApp。然后我使用此代码购买 InApp 购买,它工作正常:
try
{
await CurrentAppProxy.RequestProductPurchaseAsync(PremiumName, false);
// after closing the inApp purchase dialog, test, if it was bought
if (licenseInformation.ProductLicenses[PremiumName].IsActive)
{
// set the local flag
IsPremium = true;
dialog = new MessageDialog(resourceLoader.GetString("ThanksForPremium"));
await dialog.ShowAsync();
}
// else do not show anything
}
catch (Exception)
{
// failed buying the premium
dialog = new MessageDialog(resourceLoader.GetString("ErrorBuyingPremium"));
dialog.ShowAsync();
}
编辑:在访问这些属性之前,我使用以下命令在 Debug模式下初始化 CurrentAppSimulator:
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test-purchase.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
在 test-purchase.xml 的底部我得到了:
<LicenseInformation>
<App>
<IsActive>true</IsActive>
<IsTrial>false</IsTrial>
</App>
<Product ProductId="premium">
<IsActive>false</IsActive>
</Product>
</LicenseInformation>
关于c# - 使用 CurrentAppSimulator 进行应用内购买开发测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376049/