iOS 7中不推荐使用针对应用内购买的transactionReceipt.有什么可以替换它?

use*_*ajo 25 objective-c nsarray in-app-purchase ios7 xcode5

在iOS 7中,在SKPaymentTransaction类上,属性transactionReceipt:

// Only valid if state is SKPaymentTransactionStatePurchased.

 @property(nonatomic, readonly) NSData *transactionReceipt
Run Code Online (Sandbox Code Playgroud)

...已被弃用.但是,在我的代码中,我创建了一个InAppPurchase类,并且在我控制方法购买的方法中,我在代码中使用了委托方法,它就像:

- (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'             //
                    //------------------------------------------//

    }
   }
  }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

lod*_*ock 27

您可以将收据作为mainBundle的appStoreReceiptURL的内容.您可以找到参考资料:developer.apple.com

这是未经测试的代码,但在我的头脑中,我会说:

[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]
Run Code Online (Sandbox Code Playgroud)

应该得到与transactionReceipt用来返回相同的结果.

  • 我找不到任何文档来验证这一点.`appStoreReceiptURL`的文档明确指出这是针对捆绑包的App Store收据(不适用于应用内购买收据).此外,这对于应用内购买收据没有任何意义,因为您可能有多个订阅,例如,您可能会单独订阅视频流应用中的新闻,体育和电影频道. (34认同)
  • 我在`[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]]`和`transactionReceipt`之间得到了不同的数据.为了验证沙箱中的收据,"appStoreReceiptURL"的数据作为带有""状态"的无效收据生成:21002`但不推荐使用的`transactionReceipt`有效,"status":0`. (14认同)
  • 如果有多个交易怎么办? (9认同)
  • 有很多混淆和一个非常简单的解释:你从appStoreReceiptURL获得的收据包含有关你的应用程序的_all_交易的信息,除了耗材和不可更新的订阅只包括一次(我相信消费品或不可更新的订阅在你的交易队列中).这解决了如果用户进行两次购买会发生什么的混淆:您获得两个不同的交易,但收据将包含它们. (4认同)