当使用StoreContext.RequestPurchaseAsync()从WPF桌面应用程序执行应用程序内购买时,Windows.services.Store命名空间带有扩展错误消息的StorePurchaseResult “值不在预期的范围内。”Windows应用商店购买问题“价值不符合预期范围”
我们的应用程序已发布并可从Windows应用商店下载。
它使用DesktopAppConverter工具转换。我们根据Store(Identity Name,Publisher ...)中的描述设置manifest.appx。
我们按照下面提供的说明,使用C#从使用桌面桥接器的Windows桌面应用程序的UI线程中进行应用内购买。
https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials https://docs.microsoft.com/en-us/windows/uwp/monetize/enable-in-app-purchases-of-apps-and-add-ons
在我们的应用程序的代码,我们声明IInitializeWithWindow接口:
[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
然后,当我们的应用程序启动时,我们得到了StoreContext(存储到storeContext_属性),使用单用户方式:
// Init the store context
storeContext_ = StoreContext.GetDefault();
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext_;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
在此之后,我们设法检索S toreLicense(存储到storeLicense_属性),并列出相关的店内产品没有任何错误
// Get the current user license
storeLicense_ = await storeContext_.GetAppLicenseAsync();
if (storeLicense_ == null)
{
MessageBox.Show("An error occurred while retrieving the license.", "StoreLicenseApp Error");
return;
}
// Create a filtered list of the product AddOns I care about
string[] filterList = new string[] { "Durable" };
// Get list of Add Ons this app can sell, filtering for the types we know about
StoreProductQueryResult addOns = await storeContext_.GetAssociatedStoreProductsAsync(filterList);
if (addOns.ExtendedError != null)
{
MessageBox.Show("Impossible to retreive the list of the products on the store.\n" + addOns.ExtendedError.Message,
"Get Associated Store Products Error");
}
一旦产品的店铺ID是从商店retreived,我们等待用户点击购买按钮调用下面的回调。
private async void PurchaseButton_Clicked(object sender, RoutedEventArgs e)
{
StorePurchaseResult result = await storeContext_.RequestPurchaseAsync(selectedStoreId);
// Capture the error message for the operation, if any.
string extendedError = string.Empty;
if (result.ExtendedError != null)
{
extendedError = result.ExtendedError.Message;
}
[...]
}
RequestPurchaseAsync()
返回一个错误,而不是显示用于购买产品的Metro接口。 这里是扩展错误返回:
消息=“价值不在预期的范围内”。
的HResult = -2147024809
如何解决这个问题的任何线索?
就根据此错误信息,我们不能查找原因为发生故障的请求。如果可能,你能否提供你提供的产品ID(对于父应用程序和IAP产品)? –
嗨Mattew,这里是父应用程序一个9NFMR9KZRHTV和IAP是9PHL59JKBHNC – jarne
您可以运行** WSCOLLECT **并提供商店日志吗? –