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
相关产品推荐
相关产品推荐

