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

Unity IAP 5.1.2调用StoreController.FetchProducts无响应问题求助

Unity IAP 5.1.2 调用FetchProductsWithNoRetries无回调问题解决

可能的原因及修正方案:

  • 未验证商店连接状态
    你通过await storeController.Connect()发起连接,但未确认连接是否成功。如果连接失败(网络问题、配置错误等),后续的商品获取请求会静默无响应。在Connect后添加状态校验:

    try
    {
        await storeController.Connect();
        if (!storeController.isConnected)
        {
            Debug.LogError("[IAP] 商店连接未建立");
            return;
        }
        Debug.Log("[IAP] 商店连接成功");
    }
    catch (Exception e)
    {
        Debug.LogError("[IAP] 连接失败原因: " + e.Message);
        return;
    }
    
  • 产品ID配置不匹配
    创建ProductDefinition时需确保ID与Google Play后台配置的完全一致,Unity IAP 5.x中可显式指定商店类型,避免歧义:

    var productsToFetch = new List<ProductDefinition>
    {
        new ProductDefinition("ProductIdA", ProductType.Consumable, GooglePlay.Name),
        new ProductDefinition("ProductIdB", ProductType.Consumable, GooglePlay.Name)
    };
    
  • 改用异步await替代回调
    FetchProductsWithNoRetries的回调模式在部分场景下可能因线程或实例问题丢失响应,建议改用Unity IAP 5.x提供的异步方法,直接通过try-catch捕获结果:

    try
    {
        var fetchedProducts = await storeController.FetchProductsWithNoRetriesAsync(productsToFetch);
        Debug.Log("[IAP] 获取商品成功,数量:" + fetchedProducts.Count);
        if (fetchedProducts.Count == 0)
        {
            Debug.LogWarning("[IAP] 商品列表为空,请检查后台配置");
        }
    }
    catch (ProductFetchFailedException e)
    {
        Debug.LogError("[IAP] 获取商品失败:" + e.FailureReason);
    }
    

    这种方式无需依赖回调,错误信息更直接。

  • 检查Unity IAP基础配置
    确认以下配置是否正确:

    • Unity IAP设置中已填入Google Play应用ID
    • Google Play开发者后台已启用Billing服务
    • 测试设备已登录对应Google账号,且应用已上传至Google Play(至少为内部测试版本)

内容的提问来源于stack exchange,提问作者누더기

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.11 10:24:53