c# - 使用 CurrentAppSimulator 进行应用内购买开发测试

标签 c# microsoft-metro windows-runtime

我已经使用 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/

相关文章:

c# - 集中 MEF 组合

c# - 类似于 SQL Server Management Studio 的 WinForms DataGridView 行为

javascript - Windows 应用商店应用程序 - 从辅助磁贴启动时执行单个任务

windows-8 - 类似于 GridView 的页面,但具有静态组,并且每个组部分将具有不同的布局

c++ - 使用 Win RT 从相机捕捉快照

windows - MinGW/海湾合作委员会 : The application was unable to start correctly (0xc000007b)

wpf - 电子节目指南 (EPG) XAML

c# - WPF MessageBox 与 MVVM 模式?

c# - 如何训练使用我的代码实现 system.speech 和 SpeechRecognitionEngine 的用户

google-maps-api-3 - Google Places API 和 Windows 8 Metro Style 应用程序