Created
July 12, 2015 19:18
-
-
Save madewulf/4ebec292b77db3dd4e3a to your computer and use it in GitHub Desktop.
IAP receipt on device verification
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
- (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