0

The code of Auto-renewable Subscription works fine iOS, I copy the same code to Mac Cocoa for testing in a new app(sandbox). The purchase process also works fine, but problem happens when it's expired and I try to restore purchased, it always give the oldest transaction but not the latest.

In iOS, receipInfo.lastObject gives the latest correct one

In MacOS, the latest one is the first one of the array, receipInfo.firstObject

This should not be different, since both iOS and MacOs use the same StoreKit, but just have no idea why this happens.

do {
        let requestData = try JSONSerialization.data(withJSONObject: jsonDict, options: JSONSerialization.WritingOptions.prettyPrinted)
        let storeURL = URL(string: verifyReceiptURL)!
        var storeRequest = URLRequest(url: storeURL)
        storeRequest.httpMethod = "POST"
        storeRequest.httpBody = requestData
                
        let session = URLSession(configuration: URLSessionConfiguration.default)
        let task = session.dataTask(with: storeRequest, completionHandler: { [weak self] (data, response, error) in
            if let data = data , error == nil {
                do {
                    let jsonResponse = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers)
                            
                     guard let receiptInfo: NSArray = jsonResponse["latest_receipt_info"] as? NSArray else {
                         return
                     }
                     debugPrint(receiptInfo)
                     let info = receiptInfo.lastObject
                     ......
                            
                } catch let parseError {
                    print(parseError)
                }
            }
        })
        task.resume()
     } catch let parseError {
         print(parseError)
  }
jdleung
  • 1,088
  • 2
  • 10
  • 26

1 Answers1

0

I recently found in iOS the latest is first in the array. In my app I had it set to check the last item in the array and it was returning old data.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Swick
  • 167
  • 1
  • 8