Я тестировал IAP типа Consumable в среде Sandbox. Я хочу убедиться, что купленный мной товар действителен или нет. но результат всегда возвращается со статусом «21004». Я ничего не делаю с секретом общего доступа. Итак, вы можете посмотреть пример кода, за которым я следую Apple, когда мне удается купить товар:
- (void)verifyStatus:(SKPaymentTransaction *)transaction {
NSData *receiptData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSError *receiptError;
BOOL isPresent = [[[NSBundle mainBundle] appStoreReceiptURL] checkResourceIsReachableAndReturnError:&receiptError];
if (!isPresent) {
NSLog(@"Validation failed");
}
NSString *receiptStr = [receiptData base64EncodedStringWithOptions:0];
NSDictionary *requestContents = @{@"receipt-data":receiptStr};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:nil];
if (!requestData) { /* ... Handle error ... */ }
NSURL *storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];
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];
NSLog(@"Respond : %@",jsonResponse);
if (!jsonResponse) { /* ... Handle error ...*/ }
/* ... Send a response back to the device ... */
}
}];
}
В чем проблема? Пожалуйста, поделитесь своим опытом. Спасибо