类型“Product.SubscriptionInfo.RenewalInfo”的Swift值没有成员“renewalDate

omvjsjqw  于 12个月前  发布在  Swift
关注(0)|答案(1)|浏览(123)

在iOS 16.5不支持Xcode 14之后,我下载了Xcode 15 beta 2来开发一个应用程序。我已经准备好将我的应用程序提交到App Store,但我必须使用Xcode 14.3.1,因为似乎无法使用beta上传。当我在Xcode 14中构建时,我得到了以下关于StoreKit的错误:Value of type 'Product.SubscriptionInfo.RenewalInfo' has no member 'renewalDate-我已经检查了文档,它支持iOS 15+(我的目标是iOS 16+)。
https://developer.apple.com/documentation/storekit/product/subscriptioninfo/renewalinfo/4193529-renewaldate
我需要从storeKit获取续订信息,如何解决此错误?
下面是我的方法:

func mapped(from product: Product, renewal: Product.SubscriptionInfo.RenewalInfo?) {
        id = product.id
        level = setLevel(for: product.id)
        if let renewalInfo = renewal {
            renewalDate  = renewalInfo.renewalDate // It says this doesn't exist??
            billingRetry = renewalInfo.isInBillingRetry
        } else {
            Task {
                guard let transaction = await product.latestTransaction else { return }
                renewalDate = transaction.signedDate
            }
        }
    }
    ```
yr9zkbsy

yr9zkbsy1#

这似乎是Apple文档(2023)中的错误,当您访问Xcode中Product.SubscriptionInfo.RenewalInfo的定义时,没有renewalDate属性。

当你打印renewalInfo对象时,你可以在那里看到它。

if let item = try await products[sku]?.subscription?.status.first {
 if let verificationResult = item.renewalInfo {
  let renewalInfo = try verificationResult.payloadValue
   print(renewalInfo)

产出:

{
  "autoRenewProductId" : "product_B",
  "autoRenewStatus" : 0,
  "deviceVerification" : "MrWi...",
  "deviceVerificationNonce" : "3d...",
  "environment" : "Sandbox",
  "originalTransactionId" : "2000000425656293",
  "productId" : "product_A",
  "recentSubscriptionStartDate" : 1696256551000,
  "renewalDate" : 1696260151000,
  "signedDate" : 1696257225930
}

对于debugDescriptionjsonRepresentation也是如此。
它很丑,绝对不认为这是最好的解决方案,但我们从jsonRepresentation解析了它。
使用XCode 14.2

相关问题