0

我一直在尝试在模拟器中进行应用程序购买测试,但都是徒劳的。商店示例确实有效,但是当我尝试在我的应用程序中实现类似的行为时,它并没有像我想要的那样模拟。我有一个设置页面和所有注释页面,我需要将它们作为高级功能。该应用程序默认免费。

这是我的 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); 

该值仍然是错误的。有什么我想念的吗?

4

2 回答 2

0

您忘记将 proxyFile 加载到 CurrentAppSimulator 中。

await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
于 2014-12-30T09:26:40.947 回答
0

我不确定这是否重要,但我输入IsTrial == True了我的 xml。但是我发现,更重要的是,要能够成功购买任何东西,您应该首先购买应用程序本身调用

Windows.ApplicationModel.Store.CurrentAppSimulator.RequestAppPurchaseAsync()

您只需在会话期间执行一次此操作,在您购买应用程序后,您就可以购买任何产品。希望这可以帮助。

于 2014-08-29T03:41:22.993 回答