You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity IAP订阅按钮无响应,如何排查问题?

Unity IAP订阅购买无反应排查方案

问题背景

已完成Unity IAP订阅功能的按钮配置、IAP Catalog配置,且Unity IAP与游戏服务已自动初始化。将应用上传至Google Play Console封闭测试后,安装到手机点击购买按钮无任何反应。


排查步骤

1. 检查Google Play Console配置

  • 确认封闭测试名单已添加你使用的测试Google账号,且账号已接受测试邀请
  • 检查Google Play后台的订阅商品状态为激活,商品ID需与Unity IAP Catalog中的yearly-premium、monthly-premium完全一致(区分大小写、特殊字符)
  • 验证应用签名配置:Unity打包使用的签名需与Google Play Console中的签名一致(若启用Google Play App Signing,需确认上传密钥正确)

2. 验证Unity IAP初始化与日志输出

  • 补充初始化成功/失败的日志,确认IAP是否正常初始化:
    private void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        Debug.Log("IAP初始化成功");
        m_StoreController = controller;
        m_StoreExtensionProvider = extensions;
    }
    
    private void OnInitializeFailed(InitializationFailureReason error)
    {
        Debug.LogError("IAP初始化失败: " + error);
    }
    
  • 打开LogCat(Unity编辑器或Android Studio),过滤UnityIAP关键词,查看点击购买时的错误日志,比如商品未找到、权限不足等信息
  • 确认OnPurchaseCompleted方法已正确绑定到购买完成回调:
    UnityPurchasing.Instance.onPurchaseComplete += OnPurchaseCompleted;
    

3. 检查购买按钮的逻辑绑定

  • 确认按钮点击事件已正确关联到触发购买的方法,方法内需正确调用IAP购买接口:
    public void PurchaseSubscription(string productId)
    {
        if (m_StoreController == null || m_StoreExtensionProvider == null)
        {
            Debug.LogError("IAP未初始化");
            return;
        }
        Product product = m_StoreController.products.WithID(productId);
        if (product != null && product.availableToPurchase)
        {
            Debug.Log("发起购买: " + product.definition.id);
            m_StoreController.InitiatePurchase(product);
        }
        else
        {
            Debug.LogError("商品不可购买: " + productId);
        }
    }
    
  • 检查是否在购买方法中正确判断了商品的可购买状态

4. 设备与账号环境检查

  • 测试设备必须登录已加入封闭测试名单的Google账号,禁止使用未授权账号
  • 确保设备的Google Play服务为最新版本,且网络可正常访问Google服务
  • 检查设备Google Play设置中,已开启应用内购买权限

补充代码

IAPListener的OnPurchaseCompleted方法

public void OnPurchaseCompleted(Product product)
{
    switch (product.definition.id)
    {
        case "yearly-premium":
            Invoke("ActivateSubscription",0.1f);
            break;
        case "monthly-premium":
            Invoke("ActivateSubscription",0.1f);
            break;
    }
}

按钮中的ActivateSubscription方法

public void ActivateSubscription()
{
    PlayerPrefs.SetInt("Subscription",1);
    PurchaseWindowState(false);
}

内容的提问来源于stack exchange,提问作者Justit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 02:50:00