transactionReceipt for in-app purchase is deprecated in iOS 7. What can I replace it with?

▼魔方 西西 提交于 2019-12-18 11:05:16

问题


In iOS 7, on the SKPaymentTransaction class, the property transactionReceipt:

// Only valid if state is SKPaymentTransactionStatePurchased.

 @property(nonatomic, readonly) NSData *transactionReceipt

…is deprecated. But, in my code, I created a InAppPurchase class, and in my method for controlling how is the method buying, I'm using the delegate method in my code and it's like:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

for (SKPaymentTransaction *transaction in transactions) {

    switch (transaction.transactionState) {

        case SKPaymentTransactionStatePurchasing:

                       // code and bla bla bla    
                          [self initPurchase];  
                          NSLog(@"PASO 1");          

            break;

        case SKPaymentTransactionStatePurchased:

                      // this is successfully purchased!
                            purchased = TRUE;
                            NSLog(@"PASO 2");
                           [self isPurchased];

                 NSLog(@"purchased %s", purchased? "true" : "false");

                     //  and return the transaction data

  if ([delegate respondsToSelector:@selector(successfulPurchase:restored:identifier:receipt:)])
  [delegate successfulPurchase:self restored:NO identifier:transaction.payment.productIdentifier receipt:transaction.transactionReceipt];

                     // and more code bla bla bla 

            break;

        case SKPaymentTransactionStateRestored:

                    // and more code bla bla bla 

                          [self restorePurchase];
                          NSLog(@"PASO 3");

            break;

        case SKPaymentTransactionStateFailed:

                    // and more code bla bla bla 

                           [self failedNotification];
                           NSLog(@"PASO 4");

            break;

                    //------------------------------------------//
                    //               THANKS GUYS                //
                    //          GRETTINGS FROM BOLIVIA          //
                    //             ROCK ON!!!! n_n'             //
                    //------------------------------------------//

    }
   }
  }


回答1:


You can get the receipt as the contents of the mainBundle's appStoreReceiptURL. You can find references: developer.apple.com

This is untested code, but off the top of my head, I'd say something along the lines of:

[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]

should get you the same result that transactionReceipt used to return.




回答2:


In case anyone maybe also confused about this problem (Maybe You also read an a little outdated tutorial like me...)

Please checkout WWDC 2014 Session 305 Preventing Unauthorized Purchases with Receipts. It covers both iOS & OS X, clear and comprehensive.



来源:https://stackoverflow.com/questions/18903879/transactionreceipt-for-in-app-purchase-is-deprecated-in-ios-7-what-can-i-replac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!