我一直在尝试在模拟器中进行应用程序购买测试,但都是徒劳的。商店示例确实有效,但是当我尝试在我的应用程序中实现类似的行为时,它并没有像我想要的那样模拟。我有一个设置页面和所有注释页面,我需要将它们作为高级功能。该应用程序默认免费。
这是我的 xml 文件。我已经创建为示例应用程序中的那个。因为我的应用程序默认是免费的,所以我需要吗?
<?xml version="1.0" encoding="utf-8" ?>
<CurrentApp>
<LicenseInformation>
<App>
<IsActive>true</IsActive>
<IsTrial>false</IsTrial>
</App>
<Product ProductId="Settings">
<IsActive>true</IsActive>
</Product>
<Product ProductId="AllNotes">
<IsActive>false</IsActive>
</Product>
</LicenseInformation>
</CurrentApp>
其余代码写在设置页面的 OnNavigatedTo 函数上。
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
var productLicense = licenseInformation.ProductLicenses["Settings"];
if (!productLicense.IsActive)
{
var messageDialog = new MessageDialog("You need to buy the Settings option", "Buy");
messageDialog.Commands.Add(new UICommand("Buy", null, 0));
var commandChosen = await messageDialog.ShowAsync();
if ((int)commandChosen.Id == 0)
{
await CurrentAppSimulator.RequestProductPurchaseAsync("Settings", true);
if (licenseInformation.ProductLicenses["Settings"].IsActive)
{
InitializeUI();
}
}
}
}
因此,即使我尝试购买产品,也等待
CurrentAppSimulator.RequestProductPurchaseAsync("Settings", true);
该值仍然是错误的。有什么我想念的吗?