我正在使用應用內購買爲iPhone和iPad創建應用,但是我在iPhone上遇到問題。當我點擊其中一個可購買商品時,一旦SKPayment
被添加到SKPaymentQueue
,我的ViewController就會自行解除付款,而未處理付款。這導致了一個崩潰,直到我加入[[SKPaymentQueue defaultQueue] removeTransactionObserver:self]
到我的dealloc
。應用內購買UIViewController在SKPaymentQueue之後被駁回addPayment
一旦我重新啓動應用程序,它將按預期處理付款,並向用戶授予他們購買的內容。除非已完全退出並重新啓動,否則不會處理付款。
我加入支付方式如下:
- (void)purchaseConnector: (NSIndexPath *)indexPath
{
SKProduct *selectedProduct = productDetailsList[indexPath.row];
SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
後,它進入這裏:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)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];
break;
default:
break;
}
}
}
事務的狀態是SKPaymentTransactionStatePurchasing
從而繼續保持,在視圖控制器駁回之後,並彈出「確認您的應用內購買」UIAlert
。
再說一次,所有的iPad都能夠完美地工作,這些問題只會在iPhone上出現。
編輯
我想澄清,問題是這家店的ViewController被解僱。我從來沒有解僱過它,似乎也無法跨過收到命令的地方。解僱不會發生在iPad上,只是iPhone。