在我的iPhone應用程序中,使用StoreKit讓用戶可以在應用程序中購買訂閱。我遇到的問題是,突然每次啓動應用程序SKPaymentTransactionStatePurchased都會發送給觀察者,因此應用程序試圖一次又一次地購買訂閱。如果我嘗試從應用中的訂閱列表再次購買訂閱,我會收到一條消息,內容爲「您已經購買了此應用內購買,但尚未下載。」然後使用SKErrorPaymentCancelled調用failedTransaction。iPhone SDK StoreKit的問題
編輯:我現在已經在蘋果開發者論壇上發現了很多的線程這一點,例如:https://devforums.apple.com/thread/73818和/線程/ 73572,好像很多開發商有同樣的問題..
這是我正在使用的代碼,你能看到它有什麼問題嗎?
-(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];
default:
break;
}
}
}
-(void) failedTransaction: (SKPaymentTransaction *)transaction
{
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(@"Error");
} else {
NSLog(@"Cancel");
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
-(void) restoreTransaction: (SKPaymentTransaction *)transaction
{
[self subscribe:transaction];
}
-(void) completeTransaction: (SKPaymentTransaction *)transaction
{
[self subscribe:transaction];
}
-(void)subscribe: (SKPaymentTransaction*)transaction {
NSInteger errorCode = //Connects to my server that verifies receipt with Apple server etc..
if (errorCode==0) {
[self provideContent];
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
感謝您的回答!在問我這個問題後,我在Apple開發者論壇中發現了幾個主題,許多人都遇到同樣的問題。由於我們一直使用StoreKit幾乎一年都沒有問題,所以一定會有變化... – mrrmatinsi 2010-11-03 22:05:36