Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4585718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:32:08+00:00 2026-05-21T21:32:08+00:00

I build a project for in-app purchase. There are parts of source code bellow:

  • 0

I build a project for in-app purchase. There are parts of source code bellow:

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    NSLog(@"paymentQueue update");
    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) completeTransaction: (SKPaymentTransaction *)transaction
{
    NSLog(@"completeTransaction");
    // Your application should implement these two methods.
    [self recordTransaction: transaction];
    [self provideContent: transaction.payment.productIdentifier];
    // Remove the transaction from the payment queue.
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
    NSLog(@"restoreTransaction");
    [self recordTransaction: transaction];
    [self provideContent: transaction.originalTransaction.payment.productIdentifier];
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
    NSLog(@"failedTransaction");
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        // Optionally, display an error here.
    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

//Optional, record the transaction infomation
- (void) recordTransaction: (SKPaymentTransaction *)transaction{

    receipt=transaction.transactionReceipt;

    [[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:@"proUpgradeTransactionReceipt" ];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self sendReceipt:receipt];

    expiredTime=transaction.transactionDate;
}

I can add payment and make purchase in sandbox successfully,
but the finished transactions doesn’t removed from the defaultQueue after finishTransaction: executed.
The defaultQueue accumulates when I add payment.

Does I make some mistake?
Thanks for any helps.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:32:08+00:00Added an answer on May 21, 2026 at 9:32 pm

    It’s really my fault…
    I duplicate StoreObserver object everytime I do purchase
    After I add a flag to prevent the duplication(as follows), the bug is fixed.

    static bool hasAddObserver=NO;
        -(void) recvPurchase:(NSString *)purchaseString{
            //check user's in-app purchase status
            if ([self CanPurchase]) {
                    /*=====================================*/
                if (!hasAddObserver) {//flag to fix this bug
                    /*=====================================*/
                    observer=[[StoreObserver alloc]init];
                    [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
                    hasAddObserver=YES;
                }
                SKPayment *payment = [SKPayment paymentWithProductIdentifier:purchaseString];
                [[SKPaymentQueue defaultQueue] addPayment:payment];
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to build a project from another C# app: var
As you all know, when you build a project with an app.config file it
I'm a Beginner, trying to build a django project that runs on Google App
So I built my project and I have a .app file from my BUILD
In a ruby on rails app, I build an array of Project Names and
I'm trying to build a medium-size project in Eclipse. It consists of main app
If I change the project build target in a Phonegap app I get Unfortunately
I build an in-app purchase application. I don't know why Android Market return CANCELED
We have CC.NET setup on our ASP.NET app. When we build the project, the
I have created a Mac app that can generate iphone ebook app project source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.