Created
November 6, 2015 03:54
-
-
Save wisaruthk/9268a8bcb81458a7587e to your computer and use it in GitHub Desktop.
iOS Receipt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initial Receipt | |
let receiptURL:NSURL? = NSBundle.mainBundle().appStoreReceiptURL | |
let data:NSData? = NSData(contentsOfURL: receiptURL!); | |
if(data == nil){ | |
// No local receipt | |
print("No local receipt") | |
} else { | |
let temp = data!.base64EncodedStringWithOptions([]) | |
let requestContent:NSDictionary = NSDictionary(object: temp, forKey: "receipt-data") | |
var requestData:NSData? = nil | |
do { | |
try requestData = NSJSONSerialization.dataWithJSONObject(requestContent,options: []) | |
} catch { | |
print("error \(error)") | |
} | |
let storeURL:NSURL! = NSURL(string: "https://sandbox.itunes.apple.com/verifyReceipt" ) | |
let storeRequest:NSMutableURLRequest = NSMutableURLRequest(URL: storeURL) | |
storeRequest.HTTPMethod = "POST"; | |
storeRequest.HTTPBody = requestData; | |
let queue:NSOperationQueue = NSOperationQueue() | |
NSURLConnection.sendAsynchronousRequest(storeRequest, queue: queue, completionHandler: { (resp:NSURLResponse?, data:NSData?, error:NSError?) -> Void in | |
// | |
print("store request success with data \(data)"); | |
var result:AnyObject? = nil | |
do { | |
try result = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) | |
//try result! = NSJSONSerialization.JSONObjectWithData(data!,0) as! NSDictionary; | |
}catch { | |
print("error \(error)"); | |
} | |
print("urlresp \(resp)"); | |
print("result = \(result)"); | |
print("error= \(error)"); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment