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 8070479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:24:29+00:00 2026-06-05T13:24:29+00:00

i am working inapp purchase project in iOS sdk.i have prepared inapp purchase class

  • 0

i am working inapp purchase project in iOS sdk.i have prepared inapp purchase class for purchasing app from appstore with enable inner contents of the project.but, my problem is SKPaymentQueue doesn’t finish working on my class.here’s code of my inapp purchase class:

- (void)purchase {
    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.test"];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];

}

- (void)provideContent:(NSString *)productIdentifier {

    NSLog(@"Toggling flag for: %@", productIdentifier);
    [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:productIdentifier];
    [[NSUserDefaults standardUserDefaults] synchronize];
    //[_purchasedProducts addObject:productIdentifier];

    [[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchasedNotification object:productIdentifier];

}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {

    NSLog(@"completeTransaction...");

    //[self recordTransaction: transaction];
    [self provideContent: transaction.payment.productIdentifier];
    [[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 {

    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
    }


    [[NSNotificationCenter defaultCenter] removeObserver:self name:kProductPurchaseFailedNotification object:transaction];


    [[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchaseFailedNotification object:transaction];


    //[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName" object:transaction];

    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

}



- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

    for (SKPaymentTransaction *transaction in transactions) {

        switch (transaction.transactionState) {

            case SKPaymentTransactionStatePurchasing:

                break;

            case SKPaymentTransactionStatePurchased:
                [self completeTransaction:transaction];
                //[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                break;

            case SKPaymentTransactionStateRestored:
                //[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                [self restoreTransaction:transaction];

                break;

            case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled) {
                    NSLog(@"An error encounterd");
                }
                else {
                    NSLog(@"Cancelled!");
                }
                //[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                [self failedTransaction:transaction];

                break;

        }

    }

}

- (void)dealloc
{
    [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

    [request release];
    [super dealloc];

}

that’s line doesn’t work on my class [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; transaction doesn’t finish.
and my another problem is nsnotificationcenter calls multiple times like if i click first time it’s call only one time no problem,another time it’s nsnotificationcenter calls 3 times.

  • 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-06-05T13:24:30+00:00Added an answer on June 5, 2026 at 1:24 pm

    i got solution your problem is addTransaction server duplicate to your issue,

    try below code it’s must working:

    static bool hasAddObserver=NO;
    
    - (void)purchase {
        if (!hasAddObserver) {//flag to fix this bug
            /*=====================================*/
            [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
            hasAddObserver=YES;
        }
        SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.test"];
        //[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    
    }
    
    
    - (void)provideContent:(NSString *)productIdentifier {
    
        NSLog(@"Toggling flag for: %@", productIdentifier);
        [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:productIdentifier];
        [[NSUserDefaults standardUserDefaults] synchronize];
        //[_purchasedProducts addObject:productIdentifier];
    
        [[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchasedNotification object:productIdentifier];
    
    }
    
    - (void)completeTransaction:(SKPaymentTransaction *)transaction {
    
        NSLog(@"completeTransaction...");
    
        //[self recordTransaction: transaction];
        [self provideContent: transaction.payment.productIdentifier];
        [[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 {
    
        if (transaction.error.code != SKErrorPaymentCancelled)
        {
            NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
        }
    
    
    
    
        [[NSNotificationCenter defaultCenter] postNotificationName:kProductPurchaseFailedNotification object:transaction];
    
    
        //[[NSNotificationCenter defaultCenter] postNotificationName:@"NotificationName" object:transaction];
    
        [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    
    }
    
    
    
    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    
        for (SKPaymentTransaction *transaction in transactions) {
    
            switch (transaction.transactionState) {
    
                case SKPaymentTransactionStatePurchasing:
    
                    break;
    
                case SKPaymentTransactionStatePurchased:
                    //[self completeTransaction:transaction];
                    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    
                    break;
    
                case SKPaymentTransactionStateRestored:
                    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                    //[self restoreTransaction:transaction];
    
                    break;
    
                case SKPaymentTransactionStateFailed:
                    if (transaction.error.code != SKErrorPaymentCancelled) {
                        NSLog(@"An error encounterd");
                    }
                    else {
                        NSLog(@"Cancelled!");
                    }
                    //[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    
                    [self failedTransaction:transaction];
    
                    break;
    
            }
    
        }
    
    }
    
    - (void)dealloc
    {
        [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
    
        [request release];
        [super dealloc];
    
    }
    

    Welcome!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working inapp-purchase project and first time for creating inapp-purchase in new app
I am new to In-App purchase feature in iOS. I am working on an
I have developed iphone app with working In App Purchase. Now I want to
I am working on Google In-app purchase for an app. I have created a
my app has an inApp purchase which is working fine with my ipad having
I am working in an iOS application with in-app purchase for a client, i
I have been testing an app with in-app purchase. It has been working fine
I have implemented In App Purchase in one of the existing application, it's working
I am working to implement in-app purchase for a project and everything went well
I have successfully integrated the in app sample in my project and its working

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.