2012-01-20 66 views

回答

0

雖然我是測試取消登錄時,我不會得到這一信息,但我的代碼生成的唯一消息:

你確定你是不是觸發SKPaymentQueue Callback方法paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions的交易狀態SKPaymentTransactionStateFailed內的消息?

如果取消交易,transaction.error.code設置爲SKErrorPaymentCancelled。在這種情況下,可以省略彈出窗口或顯示自己的錯誤。

6

我相信你沒有得到「無法連接到iTunes Store 」的警報,我懷疑你在回調中顯示警報視圖。

我檢查了iOS 5和4.3。如果你沒有看到這個4.3和以上,我不會擔心。

你可以檢查用戶是否有下面的代碼

取消交易嘗試以下內restoreCompletedTransactionsFailedWithError

if (!((error.code != SKErrorPaymentCancelled) && (error.code != SKErrorPaymentNotAllowed))){ 
    NSLog(@"User Cancelled"); 
} 

代碼,我知道這看起來有點混亂,但是偉大工程,它的工作原理,即使用戶取消了恢復或新建採購。

+0

你的if語句可以更清楚地表述爲:'如果(error.code == SKErrorPaymentCancelled || error.code == SKErrorPaymentNotAllowed)'。這可以使用真值表來證明。 – Fostah

1

購買被取消時,系統不顯示任何提醒,取決於您的應用程序。請參閱the documentation中的步驟#10。

基本上,它是這樣的:

的方法你transactionObserverpaymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions當交易開始叫,成功或失敗。如果失敗,-[SKPaymentTransaction error]將包含一個常規的NSError。然後你可以檢查它的代碼並採取相應的行動。

已知的代碼是:(從<StoreKit/SKError.h>

// error codes for the SKErrorDomain 
enum { 
    SKErrorUnknown, 
    SKErrorClientInvalid,  // client is not allowed to issue the request, etc. 
    SKErrorPaymentCancelled, // user cancelled the request, etc. 
    SKErrorPaymentInvalid,  // purchase identifier was invalid, etc. 
    SKErrorPaymentNotAllowed // this device is not allowed to make the payment 
}; 

你可能要檢查至少SKErrorPaymentCancelled和SKErrorPaymentNotAllowed。

另一個有趣的問題是NSError包含一個localizedDescription,您可以在UIAlertView中顯示。這就是「不能連接iTunes Store」文本的地方。

(另外,可能與:用於測試應用程序內購買是古怪的沙盒商店,這也許可以解釋的錯誤。)