I am trying to implement subscription Model in my IAP, So I read the apple docs,
Apple mentions two methods
a) Validating Locally
b) Validating using App store (We need to have our own server to do the talking)
I used the second method and wrote the code, as mentioned in the apple docs, but
I dont have my own server,
Here is how I parsed the receipt
NSData *receipt = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data": [receipt base64EncodedStringWithOptions:0]
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];
if (!requestData) { /* ... Handle error ... */ }
// NSError *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) {
/* ... Handle error ... */
} else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (!jsonResponse) { /* ... Handle error ...*/ }
/* ... Send a response back to the device ... */
}
}];
I got the response perfectly where I can see all the details.
But apple in the docs, mentions this " It is not possible to build a trusted connection between a user’s device and the App Store directly because you don’t control either end of that connection."
So I am not sure, whether I can use this code for my production.
Secondly, the first method where apple mentions to validate the receipt locally, I want to know how to parse the receipt. They talk about some Payload which is PKCS #7 container. So how to parse this.
Regards Ranjit