首先我使用我自己的类CurrentAppProxy,它在Debug模式下使用CurrentAppSimulator,在Release中使用CurrentApp。然后,我用这个代码购买的应用程式内购买,它工作得很好:
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();
}
编辑:
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test-purchase.xml");
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
,并在:访问这些属性之前,我用这个初始化在调试模式下CurrentAppSimulator test-purchase.xml底部我得到:
<LicenseInformation>
<App>
<IsActive>true</IsActive>
<IsTrial>false</IsTrial>
</App>
<Product ProductId="premium">
<IsActive>false</IsActive>
</Product>
</LicenseInformation>
那么WindowsStoreProxy.xml文件呢?你有没有改变它? – Harry
添加了更多的代码,我使用的。 –