Xamarin Forms In App Billing 插件不起作用

Xamarin Forms In App Billing plugin does not work

我在 Xamarin Forms 项目中安装了应用内计费插件:Plugin.

首先我想在 iOS 上使用它,但是插件不起作用。它显示以下错误:Plugin.InAppBilling.Abstractions.InAppBillingPurchaseException: Cannot connect to iTunes Store at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productId, Plugin.InAppBilling.Abstractions.ItemType itemType, System.String payload, Plugin.InAppBilling.Abstractions.IInAppBillingVerifyPurchase verifyPurchase) ..

我认为我的 productId 或 payload 有误,我应该在其中输入什么? 这是我的代码:

          try
            {
                var productId = "mySKU";

                var connected = await CrossInAppBilling.Current.ConnectAsync();

                if (!connected)
                {
                    //Couldn't connect to billing, could be offline, alert user
                    return;
                }

                //try to purchase item
                var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, "payload");
                if (purchase == null)
                {
                    //Not purchased, alert the user
                }
                else
                {
                    //Purchased, save this information
                    var id = purchase.Id;
                    var token = purchase.PurchaseToken;
                    var state = purchase.State;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //Something bad has occurred, alert user
            }
            finally
            {
                //Disconnect, it is okay if we never connected
                await CrossInAppBilling.Current.DisconnectAsync();
            }

我希望有人能帮助我。提前致谢。

在使用该 nuget 之前,您必须设置 ios 设置:

https://help.apple.com/xcode/mac/current/#/dev88ff319e7

我修好了。对于所有遇到同样问题的人:我的问题是,我创建了一个 bundle id。然后我激活了自动登录 Visual Studio 并自动创建了另一个 bundle id。我选择了它,我不得不给它一个名字。我点击保存后,又变回了另一个id。问题是这些 ID 具有相同的名称。所以我在 Visual Studio 中重命名了 bundle id,它就像一个魅力。