iosstorekit2

iOS StoreKit 2 how to find `autoRenewProductId` - Value of type 'Product.SubscriptionInfo.RenewalInfo' has no member 'autoRenewProductId'


How to get information about the next product SKU? I want to get to this information autoRenewProductId, but I can't find any example of how to get there.

I tried to get there by this code:

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)") // here it is in print
                            let autoRenewProductId = renewalInfo.autoRenewProductId
                            print("autoRenewProductId: \(autoRenewProductId)") // but error here
                        } else {
                            print("no info")
                        }
                    }
                }

Print will show, it's there:

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
}

.. but I'm getting an error:

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

I'm new to Swift, maybe some cast/unwrapp/whatever needs to be done?

Additional context: XCode version 14.3., iOS 15+ enter image description here


Solution

  • ...well 🤦🏽‍♀️

    The field name is autoRenewPreference and it is probably wrongly serialized to the console log (and debugDescription and jsonRepresentation).

    See this answer: https://developer.apple.com/forums/thread/726155