4

我已经使用 CurrentAppSimulator 设置了应用内购买,并设置了获得应用内购买的功能。我还(可能)配置了我的 WindowsStoreProxy.xml 文件来处理这个问题。

但是,当我购买插件并为其指定S_OK返回值时,它仍然显示 IAP 处于非活动状态。我可以激活它的唯一方法是手动编辑 WindowsStoreProxy.xml 文件并将 Active 属性设置为 Active。这似乎很奇怪,因为 Microsoft 的 Store 示例运行良好。不过,我看不出他们有什么不同——他们仍然使用这种CurrentAppSimulator.RequestProductPurchaseAsync()方法。我在哪里错了……?

4

1 回答 1

6

首先,我使用我自己的类 CurrentAppProxy,它在调试模式下使用 CurrentAppSimulator,在发布模式下使用 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();
}

编辑:在访问这些属性之前,我使用以下命令在调试模式下初始化 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>
于 2012-11-14T13:01:09.407 回答