简体   繁体   中英

Returns many transactions on iOS In-App-Purchases receipt validation

My app contains consumable IAP products, returns more than one transactions when I call validation receipt with this code:

[[NSBundle mainBundle] appStoreReceiptURL];

Is there any way to return only last transaction ?

Is it related about restoring transactions?

I checked this Multiple receipt count for restoreCompletedTransaction inapp purchasing and this iOS in-app-purchase restore returns many transactions .

I tried to restore all purchases but it didn't work.

I'm using these lines for calling receipt:

- (void) checkReceipt {

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if(!receipt) {

}
NSError *error;
NSDictionary *requestContents = @{@"receipt-data": [receipt base64EncodedStringWithOptions:0]};
NSLog(@"requestContents:%@", requestContents);
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
                                                      options:0
                                                        error:&error];

if (!requestData) {  }

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) {


                           } else {


                           }
                       }];

}

Note: This app supports iOS 8+.

It's not related to restoring transactions, it is because apple responds with array of all in-app transactions made by the user when making a validation request. The same information is contained in the receipt if you decode it locally.

If you are looking for the last transaction made you can sort the array ascending by the purchase_date_ms and take the last one.

My objective-c is not so hot so I can't help you with sorting but this document may help: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM