应用程序内购买中断由于安全问题:没有获得SKPaymentTransactionStatePurchased?

时间:2014-04-16 07:48:49

标签: ios in-app-purchase storekit

我已经在商店中安装了应用程序,并且一小部分(<1%)的用户抱怨它不起作用的应用程序内付款。似乎如果要求用户添加信用卡OR以填写他们的安全问题,则该过程以某种方式死亡。用户将被重定向到App Store以执行操作,完成后,他们将被重定向到我们的应用程序。

用户可以告诉我他们的收据并告诉我钱已经转移。

应用内购买是非自动续订的订阅。用户完成苹果交易后,我们会将信息存储在我们的服务器上,以跟踪付款和购买到期的日期。

在我看来,没有调用SKPaymentTransactionStatePurchased就是这种情况。

我的代码:

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchasing:
            {
                NSLog(@"Purchasing Product From Store!");
            }
            break;

            case SKPaymentTransactionStatePurchased:
            {
                 NSLog(@"Purchased Product From Store! %@", transaction.description);
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                if(buyProductBlock != nil)
                {
                    buyProductBlock(TRUE, nil);
                    buyProductBlock = nil;
                }
            }
            break;

            case SKPaymentTransactionStateRestored:
            {
                //SKPaymentTransactionStateRestored is only issued after you call restoreCompletedTransactions.
                NSLog(@"Restored");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            }
            break;

            case SKPaymentTransactionStateFailed:
            {
                NSLog(@"Purchase failed %@ %@", transaction.payment.productIdentifier, transaction.payment.debugDescription);
                [[SKPaymentQueue defaultQueue] finishTransaction: transaction];

                if(buyProductBlock != nil)
                {
                    if (transaction.error.code == SKErrorPaymentCancelled)
                        buyProductBlock(FALSE, nil);
                    else
                        buyProductBlock(FALSE, transaction.error.localizedDescription);
                    buyProductBlock = nil;
                }

            }
            break;


            default:
                break;
        }
    }
}

我尝试了以下内容:

Test an Interrupted Transaction

Set a breakpoint in your transaction queue observer’s paymentQueue:updatedTransactions: method 
so you can control whether it delivers the product. Then make a purchase as usual in the test 
environment, and use the breakpoint to temporarily ignore the transaction—for example, by 
returning from the method immediately using the thread return command in LLDB. Terminate and 
relaunch your app. Store Kit calls the paymentQueue:updatedTransactions: method again shortly 
after launch; this time, let your app respond normally. Verify that your app correctly delivers 
the product and completes the transaction.

结果是在重新启动应用程序后没有调用paymentQueue:updatedTransactions。

也许这就是我的问题所在?

谢谢, Sjoerd Perfors

编辑:

因为我杀了这个块(buyProductBlock = nil),有可能首先我得到一个SKPaymentTransactionStateFailed,当用户返回应用程序时,我会得到一个SKPaymentTransactionStatePurchased,但由于该块不会被调用?

1 个答案:

答案 0 :(得分:0)

我的问题是:

  • 正如Paulw11所说:您只需在产品与服务器实际同步后完成交易。我重写了这些东西。
  • 在我的块代码中,我的声明不正确导致产品无法与服务器同步。这实际上是我的主要错误,是由我自己的代码引起的,并没有显示在这个问题中。
  • 添加&#34; addTransactionObserver&#34;当您的应用启动时,这将导致任何未完成的交易被命中为paymentQueue方法。

每个人都应该阅读:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/DeliverProduct.html