我正在尝试使用我的服务器端的收据验证.一切都很好,但有时我看到很奇怪:10次验证是可以的,但在11我得到21002错误.我不知道该怎么办.当我在启动应用程序后第一次验证收据时,有时会收到错误21002.
应用方面:
func validateReceipt(productID: String) {
let receipt = NSData(contentsOfURL: NSBundle.mainBundle().appStoreReceiptURL!)!
let receiptdata = receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
let request = NSMutableURLRequest(URL: NSURL(string: "my_server_url")!)
let session = NSURLSession.sharedSession()
request.HTTPMethod = "POST"
request.HTTPBody = receiptdata.dataUsingEncoding(NSUTF8StringEncoding)
let task = session.dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let json = try! NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary
if (error != nil) {
print(error!.localizedDescription)
let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("Error could not parse JSON: '\(jsonStr)'")
}
else {
if let parseJSON = json { …
Run Code Online (Sandbox Code Playgroud)