我设置了一个按钮来调用以下方法:
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()
我怎样才能摆脱这个错误?
答案 0 :(得分:0)
修复此问题,在RequestProductPurchaseAsync方法调用中添加try / catch ...
try
{
receipt = await CurrentApp.RequestProductPurchaseAsync("MyItem", false);
}
catch (Exception){}