【发布时间】:2017-10-19 07:28:38
【问题描述】:
我正在使用 monogame 作为游戏框架,我正在尝试在 UWP 应用中实现应用内购买功能,当我调用 RequestProductPurchaseAsync 时会引发异常。它指出:
设置后无法更改线程模式。 (HRESULT 的例外情况: 0x80010106 (RPC_E_CHANGED_MODE)) 在 Windows.ApplicationModel.Store.CurrentAppSimulator.RequestProductPurchaseAsync(字符串 产品 ID)在 Crocs_World__Xbox_Edition_.App.d__7.MoveNext()
这就是我在代码中所做的:
public async Task LoadInAppPurchaseProxyFileAsync()
{
StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");
StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
// setup application upsell message
try
{
ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();
var product1 = listing.ProductListings["product1"];
var product2 = listing.ProductListings["product2"];
}
catch (Exception e)
{
Debug.WriteLine("LoadListingInformationAsync API call failed:" + e);
}
}
private async void InAppPurchaseRefreshScenario()
{
Debug.WriteLine("InAppPurchaseRefreshScenario");
}
public async Task BuyFeature()
{
LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
if (!licenseInformation.ProductLicenses["product2"].IsActive)
{
Debug.WriteLine("Buying Product 2...");
try
{
await CurrentAppSimulator.RequestProductPurchaseAsync("product2");
if (licenseInformation.ProductLicenses["product2"].IsActive)
{
Debug.WriteLine("You bought Product 2.");
}
else
{
Debug.WriteLine("Product 2 was not purchased.");
}
}
catch (Exception e)
{
Debug.WriteLine("Unable to buy Product 2." + e);
}
}
else
{
Debug.WriteLine("You already own Product 2.");
}
}
每当我调用BuyFeature 时,它都会抛出异常。除非我在LoadInAppPurchaseProxyFileAsync 中直接调用它。然后我猜它似乎在同一个线程中。
如果我在这两种方法中都用void 替换Task,它也不起作用。如果我从 app.xaml.cs 或 game.cs 调用它也没关系。
有人知道我做错了什么吗?
谢谢,
哈利
【问题讨论】: