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

iOS StoreKit 2获取autoRenewProductId报错:RenewalInfo无此成员

获取Apple订阅autoRenewProductId字段报错问题

我需要获取订阅产品下一个SKU的autoRenewProductId信息(对应Apple官方文档的autoRenewProductId),但没找到实现示例。我写了以下Swift代码:

if let statusArr = try await products[sku]?.subscription?.status {
    for item in statusArr {
        if let verificationResult = item.renewalInfo as? VerificationResult<Product.SubscriptionInfo.RenewalInfo> {
            let renewalInfo = try verificationResult.payloadValue
            print("renewalInfo: \(renewalInfo)") // 这里打印能看到字段
            let autoRenewProductId = renewalInfo.autoRenewProductId
            print("autoRenewProductId: \(autoRenewProductId)") // 这里报错
        } else {
            print("no info")
        }
    }
}

打印结果显示该字段确实存在:

renewalInfo: {
  "autoRenewProductId" : "my_product_id",
  "autoRenewStatus" : 1,
  "deviceVerification" : "0e726xCverdmmy",
  "deviceVerificationNonce" : "5d586219noncedummy",
  "environment" : "Sandbox",
  "originalTransactionId" : "2000000425656293",
  "productId" : "my_product_id",
  "recentSubscriptionStartDate" : 1696153789000,
  "renewalDate" : 1696157462000,
  "signedDate" : 1696157131071
}

但代码访问时出现报错:

Value of type 'Product.SubscriptionInfo.RenewalInfo' has no member 'autoRenewProductId'

我是Swift新手,请问是否需要进行类型转换或解包操作?

附加环境:Xcode 14.3,iOS 15+


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 18:14:55