在消耗品InAppPurchase中,在ios5.1中找不到取消交易的委托,但在ios6.1中找到了



确认您的应用内购买后,我将取消购买。在iOS 6.1中,取消后,控制转移到- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions方法。

在iOS 5.1中,不会调用任何委托方法。所以我无法控制应用程序取消交易。

我的代码购买产品:

- (void)buyProduct:(SKProduct *)product
{
    NSLog(@"Buying %@...", product.productIdentifier);
    SKPayment * payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

委托方式:

#pragma mark SKPaymentTransactionOBserver
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    NSLog(@"updated transactions");
    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                [self failedTransaction:transaction];
                break;
            case SKPaymentTransactionStateRestored:
                [self restoreTransaction:transaction];
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"SKPaymentTransactionStatePurchasing");
                break;
            default:
                break;
        }
    };
}

请让我知道问题出在哪里。

I found the solution. It was working in both iOS in device. The Problem is of validate receipt. If you are testing inApp purchase using test user then you need to use sandbox verify receipt that is
 #define  TMS_SANDBOX_VERIFY_RECEIPT_URL @"https://sandbox.itunes.apple.com/verifyReceipt". but when you are uploading app to the appstore then you need to change it to 
#define ITMS_PROD_VERIFY_RECEIPT_URL  @"https://buy.itunes.apple.com/verifyReceipt". 
So when user download the app from the app store then for the valid receipt verification 'ITMS_PROD_VERIFY_RECEIPT_URL' is must. otherwise it will give failed receipt verification. 
So please use  #define ITMS_PROD_VERIFY_RECEIPT_URL  @"https://buy.itunes.apple.com/verifyReceipt" when you are uploading app to the app store.

最新更新