saturngod / IAPHelper

No more maintenance for this repo. Please use the https://github.com/bizz84/SwiftyStoreKit
MIT License
1.55k stars 280 forks source link

transactionReceipt in iOS7 #8

Closed sergisolanellas closed 10 years ago

sergisolanellas commented 10 years ago

Hello,

I use your contribution and it works perfect, but in a new app i created only in iOS7, appears "transactionreceipt" deprecated.

How can correct it ? Only need to change with this ?

NSURL receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData receipt = [NSData dataWithContentsOfURL:receiptURL];

Thanks

saturngod commented 10 years ago

yes. correct. I will check and update for iOS 7.

Thanks

basicallydan commented 10 years ago

Hi @saturngod - I was wondering if this was closed because it was changed or if it was closed because you acknowledged it. Is there a new method for checking the receipt of a transaction using IAPHelper? Thanks :)

sergisolanellas commented 10 years ago

Hi @basicallydan, only need to change the NSData this:

NSURL receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; NSData receipt = [NSData dataWithContentsOfURL:receiptURL];

[[IAPShare sharedHelper].iap checkReceipt:receipt AndSharedSecret:@"secret_key" onCompletion:^(NSString response, NSError error) { // Do something }

basicallydan commented 10 years ago

Thanks for your reply - Does that actually refer to the latest transaction, though? According to this documentation it's for the purchased app.

To be clear, I'm trying to use this method inside this completion block:

[[IAPShare sharedHelper].iap buyProduct:product onCompletion:^(SKPaymentTransaction* trans) {
// Stuff with trans
}

If they've purchased multiple IAPs in the app, which receipt will be returned?

sergisolanellas commented 10 years ago

Yes, I use this code:

SKProduct *product = [[IAPShare sharedHelper].iap.products objectAtIndex:[sender tag]];
 [[IAPShare sharedHelper].iap buyProduct:product onCompletion:^(SKPaymentTransaction* trans){

           if(trans.error){                
               // Show error               
            }else if(trans.transactionState == SKPaymentTransactionStatePurchased) {

                NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
                NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];

                [[IAPShare sharedHelper].iap checkReceipt:receipt AndSharedSecret:@"shared_key" onCompletion:^(NSString *response, NSError *error) {
                     // Do something
                 }
            }
}
basicallydan commented 10 years ago

So, I suppose appStoreReceiptURL returns the most recent receipt?