简体   繁体   English

应用内购买时出现COMException

[英]COMException when in-app purchase

I set up a button to call following method: 我设置了一个按钮来调用以下方法:

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

when I buy/download this item, everything is fine and the following code runs just fine: 当我购买/下载该物品时,一切都很好,并且以下代码运行得很好:

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);
      }
}

But if the user returns from the in-app dialog with the back-button or if he cancels the transaction, the code crashes at 但是,如果用户使用后退按钮从应用内对话框返回或取消交易,则代码将在崩溃

   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()

How can I get rid of this bug? 我如何摆脱这个错误?

to fix this add try/catch around RequestProductPurchaseAsync method call... 要解决此问题,请在RequestProductPurchaseAsync方法调用周围添加try / catch ...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM