【问题标题】:Unhandled crash after purchasing IAP in UWP app - Windows 10在 UWP 应用中购买 IAP 后未处理的崩溃 - Windows 10
【发布时间】:2016-03-13 12:01:39
【问题描述】:

我正在将应用内购买 IAP 添加到我的 UWP 应用中,但在测试该过程时,应用会崩溃,但只有在通过调用时显示的测试对话框批准购买后:

await CurrentAppSimulator.RequestProductPurchaseAsync(
      IAPs.CoreFeatures, false);

这是我的 ViewModel 中包含的完整功能:

private async void UnlockFeaturesNow()
{
    LicenseInformation licenseInformation = App.LicenseInformation;

    if (!licenseInformation.ProductLicense[IAPs.CoreFeatures].IsActive)
    {
        try
        {
            // The customer doesn't own this feature, so show the purchase dialog.
            await CurrentAppSimulator.RequestProductPurchaseAsyn(
                  IAPs.CoreFeatures, false);

            //Check the license state to determine if the in-app purchase was successful.
            if (!licenseInformation.ProductLicenses[IAPs.CoreFeatures].IsActive)
            {
              await this._messageBoxService.Show("features were not purchased.", 
                    "Features");
            }
            else
            {
                await this._messageBoxService.Show("features were purchased 
                successfully.", "Features");

                //Remove the purchase button from splitview popup menu.
                SectionModel unlockFeatureSection = this.Sections.FirstOrDefault
                (m => m.PageName == PageNameEnum.UnlockFeaturesPage);

                if (unlockFeatureSection != null)
                {
                    this.Sections.Remove(unlockFeatureSection);
                    unlockFeatureSection = null;
                }
            }
        }
        catch (Exception ex)
        {
            // The in-app purchase was not completed because an error occurred.
            await this._messageBoxService.Show("Failed to purchase the features for 
                  the following reason: " + ex.Message, "Features");
        }
    }
    else
    {
        // The customer already owns this feature.
    }
}

如果我取消“IAP 测试对话框”或选择“确定”以外的任何其他选项,我的应用永远不会崩溃。

如果我选择“确定”,它会告诉我我的 IAP 已成功购买,并且取决于我在应用程序中的位置,它会按预期工作,但是当我第二次点击我的汉堡菜单时,它会显示我的 SplitView 菜单,如果我点击我的应用程序上的其他任何地方它只是崩溃并显示以下错误:

"A debugger is attached to myApp.exe but not configured to debug 
this unhandled exception. To debug this exception, detach the current
debugger."

我检查了我的事件查看器以获取更多信息,这就是我发现的:

Faulting application name: MyApp.exe, version: 1.0.0.0, time stamp: 0x563304b4
Faulting module name: combase.dll, version: 10.0.10586.103, time stamp: 0x56a84cbb
Exception code: 0xc000027b
Fault offset: 0x00166d7e
Faulting process ID: 0x2138
Faulting application start time: 0x01d17a76e526db18
Faulting application path: C:\MyFolder\MyApp\bin\x86\Debug\AppX\MyApp.exe
Faulting module path: C:\WINDOWS\SYSTEM32\combase.dll
Report ID: bb041374-507f-4927-84b8-75bf7cb6df63
Faulting package full name: MyApp1.1.25.0_x86__z2199h13vtehs
Faulting package-relative application ID: App

所以看起来 Combase.dll 正在崩溃,但我不知道这个 .dll 是做什么用的,为什么它只有在选择“确定”而不是其他选项后才会崩溃。

我刚刚尝试了 Microsoft 提供的 UWP Store 示例,它使用 SplitView 并提供了我正在使用的相同 IAP(场景 2)选项,当我在购买时选择 OK “IAP 测试”对话框,一切都按预期工作,所以它会让你认为这与我的代码有关,但我很确定这不是因为应用程序在使用时永远不会崩溃,并且在 IAP 测试对话框时永远不会崩溃除非我选择“确定”选项,否则显示。

明天我将继续调查,因为我的应用程序和 Microsoft 示例之间的一大区别是我使用的是 MVVM,并且此代码在我的 ViewModel 中,而不是在 XAML 页面的 Code-Behind 中。

能否告诉我您是否遇到过此问题以及是否已设法解决?

谢谢。

【问题讨论】:

  • 您是否向商店提交了 IAP?如果您的应用程序因应用程序的发布版本而崩溃,您可以尝试使用 CurrentApp 而不是 CurrentAppSimulator。我更喜欢用这种方式测试简单的 IAP 场景
  • @MichalKania 我试试看。

标签: in-app-purchase win-universal-app windows-10-universal


【解决方案1】:

我刚刚通过侥幸找到了我的问题的答案,但我仍然无法相信 .NET 处理得如此糟糕。

一旦成功购买了IAP,罪魁祸首就是从SplitView 菜单中的Listbox 中删除“购买”选项!与CurrentAppCurrentAppSimulator 无关:

//Remove the purchase button from splitview popup menu.
SectionModel unlockFeatureSection = this.Sections.FirstOrDefault
(m => m.PageName == PageNameEnum.UnlockFeaturesPage);

if (unlockFeatureSection != null)
{
    this.Sections.Remove(unlockFeatureSection);
    unlockFeatureSection = null;
}

不刷新在SplitView 菜单中绑定到我的Listbox 的项目列表(在此实例中为部分)。所以现在,当删除项目时,我确保通过mvvmlight 引发一个事件,这将在我的 MainViewModel 中重建我的列表。

在我的 MainViewModel 中,构造函数中有以下内容:

Messenger.Default.Register<bool>(this, 
Tokens.LicenseInformationChanged, (value) =>
{
    InitializeSections();
});

我现在已将我的部分从 List 更改为 ObservableCollection

private void InitializeSections()
{
    this.Sections = (this.Sections 
       ?? new ObservableCollection<SectionModel>());

    this.Sections.Clear(); 

    .... Add sections (or not!)
}

但又一次,.NET 处理这件事的方式多么可怕!轰炸我的应用程序并抛出错误而没有抛出适当的异常是可怕的!

希望这对其他人有所帮助。

【讨论】:

    【解决方案2】:

    我认为它会崩溃,因为您应该将此代码用于您的licenseInformation

    #if DEBUG
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
    
    #else
            LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
    

    【讨论】:

    • 我使用的是你所拥有的,但没有条件语句,但我只是在调试模式下注释掉了“CurrentApp”行,但我注意到了一些东西。当调用“RequestProductPurchaseAsync”时,它是从 CurrentAppSimulator 调用的。在 MS 的 Store 应用程序中也是如此,但在不处于调试模式时如何调用它??
    • 好的,我已经更改了所有代码(仅几个地方 tbh)以在调试模式下使用 CurrentAppSimulator,在发布模式下使用 CurrentApp,包括“RequestProductPurchaseAsync”。
    猜你喜欢
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    相关资源
    最近更新 更多