COMApp内购买时异常

本文关键字:异常 COMApp | 更新日期: 2023-09-27 18:00:38

我设置了一个按钮来调用以下方法:

private async void buyTimeUP()
{
    await CurrentApp.RequestProductPurchaseAsync("MyItem", false);
    DoFullFillment();
}

当我购买/下载这个项目时,一切都很好,下面的代码运行得很好:

public void DoFullFillment()
{
    var productLicenses = CurrentApp.LicenseInformation.ProductLicenses;
    checkTransaction(productLicenses["MyItem"]);
}
private void checkTransaction(ProductLicense lic)
{
     if (lic.IsConsumable && lic.IsActive)
     {
         Debug.WriteLine("License bought");
         CurrentApp.ReportProductFulfillment(lic.ProductId);
      }
}

但是,如果用户使用后退按钮从应用程序内对话框返回,或者如果他取消了交易,则代码在崩溃

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at MyApp.Shop.<buyTimeUP>d__0.MoveNext()

我该如何摆脱这个bug?

COMApp内购买时异常

要修复此围绕RequestProductPurchaseAsync方法调用添加try/catch。。。

try
{
   receipt = await CurrentApp.RequestProductPurchaseAsync("MyItem", false);
}
catch (Exception){}