2012-11-14 15 views
4

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

但是,当我购买插件并给它一个S_OK值返回时,它仍然表示IAP处于非活动状态。我可以激活它的唯一方法是手动编辑WindowsStoreProxy.xml文件并将Active属性设置为Active。这看起来很奇怪,因为来自Microsoft的商店示例工作正常。尽管他们看不到任何不同 - 他们仍然使用CurrentAppSimulator.RequestProductPurchaseAsync()方法。我在哪里错了...?

回答

6

首先我使用我自己的类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> 
+0

那么WindowsStoreProxy.xml文件呢?你有没有改变它? – Harry

+0

添加了更多的代码,我使用的。 –