i'm desperately trying to validate a receipt for in-app in a futur IOS application written with Swift, IOS8.1
I'm using the Alamofire framework to compensate a bug in NSURLConnection for swift but still not having any return from the Apple Server.
func checkReceipt(data:NSData) {
let ITMS_PROD_VERIFY_RECEIPT_URL = "https://buy.itunes.apple.com/verifyReceipt"
let ITMS_SANDBOX_VERIFY_RECEIPT_URL = "https://sandbox.itunes.apple.com/verifyReceipt"
let base64String = self.base64forData(data)
if base64String != nil {
let decodedData = NSData(base64EncodedString: base64String!, options: NSDataBase64DecodingOptions(0))
let receiptInformation = self.dictionaryFromPlistData(decodedData!)
let payload:NSString = "{\"receipt-data\" : \"\(base64String)\"}"
println("-----------------------------------------")
println("payload \(payload)")
println("-----------------------------------------")
let payloadData:NSData = payload.dataUsingEncoding(NSUTF8StringEncoding)!
let serverURL = NSURL(string: ITMS_SANDBOX_VERIFY_RECEIPT_URL) //ITMS_PROD_VERIFY_RECEIPT_URL;
var request = NSMutableURLRequest(URL: serverURL!) // (URL:
request.HTTPMethod = "POST"
request.HTTPBody = payloadData
let (param, _) = Alamofire.ParameterEncoding.URL.encode(request, parameters: nil)
Alamofire.request(param)
.response { (request, response, data, error) in
println(request)
println(response)
println(error)
}
}
}
The feedback from the server is :
Optional(<NSHTTPURLResponse: 0x17403b760> { URL: https://sandbox.itunes.apple.com/verifyReceipt } { status code: 200, headers {
"Cache-Control" = "private, no-cache, no-store, no-transform, must-revalidate, max-age=0";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Length" = 36;
Date = "Tue, 11 Nov 2014 19:20:38 GMT";
Expires = "Tue, 11 Nov 2014 19:20:38 GMT";
"Set-Cookie" = "Pod=100; version=\"1\"; expires=Thu, 11-Dec-2014 19:20:38 GMT; path=/; domain=.apple.com, itspod=100; version=\"1\"; expires=Thu, 11-Dec-2014 19:20:38 GMT; path=/; domain=.apple.com, mzf_in=990212; version=\"1\"; path=/WebObjects; domain=.apple.com; secure; HttpOnly, mzf_dr=0; version=\"1\"; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/WebObjects; domain=.apple.com";
"apple-timing-app" = "193 ms";
"edge-control" = "no-store, cache-maxage=0";
itspod = 100;
pod = 100;
"x-apple-application-instance" = nnnnnnnn;
"x-apple-application-site" = SB;
"x-apple-jingle-correlation-key" = xxxxxxxxx;
"x-apple-lokamai-no-cache" = true;
"x-apple-orig-url" = "http://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/verifyReceipt";
"x-apple-translated-wo-url" = "/WebObjects/MZFinance.woa/wa/verifyReceipt";
"x-frame-options" = SAMEORIGIN;
"x-webobjects-loadaverage" = 0;
} })
Instead of the Application receipt...
Any help appreciated
Thanks @R00We
Swift 5 , and Alamofire (5.0.0-beta.7)
Use
request<Parameters: Encodable>
,