【问题标题】:Xamarin in app billing plugin doesn't work应用计费插件中的 Xamarin 不起作用
【发布时间】:2017-12-17 20:59:03
【问题描述】:

我在应用计费插件中遇到了 xamarin 问题。我在这篇文章中使用了 James Montemagno 在他的博客中写的几乎相同的代码 => https://blog.xamarin.com/integrating-in-app-purchases-in-mobile-apps/

我尝试了很多方法,但 PurchaseAsync 方法总是返回 null。知道如何解决这个问题吗?提前谢谢你。

       private  async void Btn_ClickAsync(object sender, System.EventArgs e)
    {
        RadioGroup radioGroup = FindViewById<RadioGroup>(Resource.Id.radioGroup1);
        RadioButton radioButton = FindViewById<RadioButton>(radioGroup.CheckedRadioButtonId);


        string selectedproduct =  radioButton.Tag.ToString();
        string a = editText1.Text, b = editText2.Text;
        try
        {
            var productId = selectedproduct;
            var connected = await CrossInAppBilling.Current.ConnectAsync();
            if (!connected)
            {
                //Couldn't connect to billing, could be offline, alert user

                new AlertDialog.Builder(this)
       .SetPositiveButton("OK", (sender2, args) =>{})
       .SetMessage("Couldn't connect to billing,")
       .SetTitle("Error")
       .Show();
                return;
            }

            //try to purchase item
            var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase,"apppayload");

            if (purchase == null)
            {
           //Not purchased, alert the user
                new AlertDialog.Builder(this)
            .SetPositiveButton("OK", (sender2, args) =>{ })
            .SetMessage("Not purchased")
            .SetTitle("Error")
            .Show();
                return;
            }
            else
            {
                //Purchased, save this information
                var id = purchase.Id;
                var token = purchase.PurchaseToken;
                var state = purchase.State;
            }
        }
        catch (InAppBillingPurchaseException purchaseEx)
        {
           Toast.MakeText(ApplicationContext, purchaseEx.InnerException.ToString(), ToastLength.Long).Show();
        }
        finally
        {
            //Disconnect, it is okay if we never connected
           await CrossInAppBilling.Current.DisconnectAsync();
        }
    }

    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data);
    }

【问题讨论】:

    标签: xamarin xamarin.android in-app-purchase in-app-billing


    【解决方案1】:

    您需要严格按照 James Montemagno 的指南进行操作。

    https://jamesmontemagno.github.io/InAppBillingPlugin/GettingStarted.html

    我已经体验过使用 Xamarin 和他的库实现这一点的全部经验。正确配置后,一切正常。

    我确实错过了 android 入门指南底部附近的一些内容,这让我很困惑。

    我自己发现的几件事:

    1. info.plist 中的捆绑包标识符必须与 itunesconnect 捆绑包 ID 匹配,才能在 ios 模拟器上查看产品列表
    2. 测试购买,让您选择的许可测试用户购买您的应用内产品,而无需向用户收取任何费用。测试购买只能用于 alpha/beta 版本。即使应用处于 Alpha 阶段,Google 也会向普通用户收费。

    【讨论】:

      【解决方案2】:

      更新您的 alpha apk 文件并重试。您必须使用应用程序的 Play 商店版本。调试应用内购买很痛苦。

      【讨论】:

        猜你喜欢
        • 2021-09-20
        • 2020-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多