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)
}