使用Apple服务器验证耗材IAP的正确方法是什么?

时间:2017-08-30 11:15:20

标签: ios iphone in-app-purchase

从iOS7 Apple弃用了SKPaymentTransaction实例的transactionReceipt属性,现在我们有一个包含所有内容的大收据。在我的应用程序中,我有几个消耗品购买。我的代码:

#pragma mark -
#pragma mark SKPaymentTransactionObserver

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

    for (SKPaymentTransaction *transaction in transactions) {

        switch (transaction.transactionState) {

            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;

           ...
    }

}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
//    [self sendRecieptToServer:transaction.transactionReceipt]; // deprecated
    [self testMainReceipt];
    [self deliverPurchaseNotificationFirIdentifier:transaction.payment.productIdentifier];
    [SKPaymentQueue.defaultQueue finishTransaction:transaction];
}

- (void)testMainReceipt {
    NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];

    [self sendRecieptToServer:receipt]; //look at the 'status' field and determine whether a good purchase or not
}

从Apple的回复中我看到'in_app'提交了一个阵列,其中包含一个项目 - 我最近的购买,无论我之前购买了多少次。 我认为消费品的购买方式如何?对于最近的购买,我总是会得到1个项目和“状态”字段的数组?还是有更好的方法?

2 个答案:

答案 0 :(得分:2)

dji_error.cpp

您需要在每次需要时购买这些商品,而且您无法再次免费下载。如果您删除并重新安装应用程序,或在新设备上安装应用程序,则可能会丢失您的耗材购买。例如,如果您在iPod touch上安装了一个游戏,并且已开始在iPhone上玩游戏,则游戏级别会同步,但您在iPhone上购买的额外健康或体验点不会同步。

消耗品可以是游戏货币,额外健康,额外经验值。

消费品无法恢复,&amp;收据也会出现一次。

您可以找到更多详情enter image description here。 您也可以查看link

答案 1 :(得分:0)

您可以使用 appStoreReceiptURL 方法,如果它不可用(在旧系统上),您可以回退到使用App Store验证SKPaymentTransaction对象的transactionReceipt属性。

有关详细信息,请参阅Validating Receipts With the App Store。 请参阅:https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW2