簡體   English   中英

iPhone SDK StoreKit問題

[英]Problems with iPhone SDK StoreKit

在我的iPhone應用程序Im中,我使用StoreKit使用戶可以在應用程序中購買訂閱。 我遇到的問題是,每當我啟動應用程序時,突然將SKPaymentTransactionStatePurchased發送給觀察者,因此該應用程序嘗試一次又一次地購買訂閱。 如果我嘗試從應用程序的訂閱列表中再次購買該訂閱,則會收到一條消息,提示您“您已經購買了此應用程序內購買功能,但尚未下載”。 然后使用SKErrorPaymentCancelled調用failedTransaction。

編輯:我現在在Apple開發人員論壇中找到了很多與此相關的線程,例如: https ://devforums.apple.com/thread/73818和/ thread / 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];
}

第一次使用StoreKit時,我遇到了確切的問題,它的發生是因為在實施代碼時,我未完成交易。

因此,啟動應用程序時,您需要遍歷隊列並完成所有事務。 您不需要覆蓋所有結果(根據上面的代碼,您已經做到了)。

與Apple支持人員交談后,我得以解決此問題。 蘋果公司似乎已經解決了這個問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM