Skip to content

Instantly share code, notes, and snippets.

@madewulf
Created July 12, 2015 19:18
Show Gist options
  • Save madewulf/4ebec292b77db3dd4e3a to your computer and use it in GitHub Desktop.
Save madewulf/4ebec292b77db3dd4e3a to your computer and use it in GitHub Desktop.
IAP receipt on device verification
- (void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
{
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
NSDictionary *requestContents = @{
@"receipt-data" : [receipt base64EncodedStringWithOptions:0]
};
NSError *error;
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];
NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];
// Make a connection to the iTunes Store on a background queue.
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
} else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"jsonReponse %@", jsonResponse);
if (!jsonResponse) { }
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment