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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:10:57+00:00 2026-05-23T20:10:57+00:00

I have a small issue with iAP. I have the code working for the

  • 0

I have a small issue with iAP. I have the code working for the most part. It’s just when the user cancels the purchase, the device doesn’t think its over and keeps it. Thus if you try to buy it again, you will buy 2 of the product…which is bad, since they only want one. I must be missing some code. I will attach a Console log so you can see whats going on.

2010-12-21 15:47:29.364[204:307] Parental-controls are disabled (I launch the iAP)
2010-12-21 15:47:33.816[204:307] Win (There are products)
2010-12-21 15:47:37.043[204:307] Buying... (I pressed buy)
2010-12-21 15:47:40.661[204:307] FailedTransaction (Essentially I canceled)
2010-12-21 15:47:40.674[204:307] DefaultAction (which is to dismiss the modal view)
2010-12-21 15:47:42.738[204:307] Parental-controls are disabled (reopen the iAP view)
2010-12-21 15:47:44.440[204:307] Win
2010-12-21 15:47:46.939[204:307] Buying...
2010-12-21 15:47:46.945[204:307] Buying...
2010-12-21 15:47:48.414[204:307] FailedTransaction
2010-12-21 15:47:48.427[204:307] DefaultAction
2010-12-21 15:47:48.437[204:307] FailedTransaction
2010-12-21 15:47:48.449[204:307] DefaultAction
2010-12-21 15:47:50.622[204:307] Parental-controls are disabled
2010-12-21 15:47:51.314[204:307] Win
2010-12-21 15:47:51.883[204:307] Buying...(see how it compounds?)
2010-12-21 15:47:51.889[204:307] Buying...
2010-12-21 15:47:51.896[204:307] Buying...
2010-12-21 15:48:10.764[204:307] Posted5
2010-12-21 15:48:10.782[204:307] Yipeee!
2010-12-21 15:48:10.810[204:307] Posted5 (It gave the users 15 credits!)
2010-12-21 15:48:10.869[204:307] Yipeee!
2010-12-21 15:48:10.897 204:307] Posted5
2010-12-21 15:48:10.912[204:307] Yipeee!

Here is the code I am running:

#import "PurchaserViewController.h"

@implementation PurchaserViewController


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"yayadaadul.com/checkcredits.php"]]];

    if ([SKPaymentQueue canMakePayments]) {
        NSLog(@"Parental-controls are disabled");

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.company.name.song"]];
        productsRequest.delegate = self;
        [productsRequest start];
    } else {
        NSLog(@"Parental-controls are enabled");
    }
}

- (IBAction)purchase {


    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.changedwe.worksinxcode.song"];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (IBAction)stop {
    [player stop];
}

- (IBAction)play {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *file = [NSString stringWithFormat:@"%@/Song.mp3", documentsDirectory];

    player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:file] error:nil];
    [player play];
}

- (void)downloadFromURL:(NSURL *)url {
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *file = [NSString stringWithFormat:@"%@/Song.mp3", documentsDirectory];

    [data writeToFile:file atomically:YES];
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if (count > 0) {
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"Win");

    } else if (!validProduct) {
        NSLog(@"No products available");


    }
}
-(IBAction)home {
    [self dismissModalViewControllerAnimated:YES];

}


- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"Buying...");
                break;
                break;

            case SKPaymentTransactionStatePurchased:
                [self downloadFromURL:[NSURL URLWithString:@""]];

                NSString *post =[NSString stringWithFormat:@"username=lol&cval=5"];

                NSString *hostStr = @"http://mysite.com/subdom/ccredit.php?";
                hostStr = [hostStr stringByAppendingString:post];
                NSLog(@"Posted5");


                NSLog(@"Yipeee!");
                [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://Action to Post.php?"]]];



                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                break;

            case SKPaymentTransactionStateRestored:
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"Restored");

                break;

            case SKPaymentTransactionStateFailed:
                NSLog(@"FailedTransaction");
            //  [self finishTransaction:transaction wasSuccessful:NO];

                if (transaction.error.code != SKErrorPaymentCancelled) {
                    NSLog(@"An error encounterd");
                }

                //You need to clear their purchases here


                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"DefaultAction");


                [self dismissModalViewControllerAnimated:YES];

                break;
        }
    }
}
  • 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-23T20:10:58+00:00Added an answer on May 23, 2026 at 8:10 pm

    It looks like you keep adding yourself as the transaction observer every time the purchase action is performed. Press it once, everything works fine. Press it again and your observer delegate methods get called twice, both for the second transaction.

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

Sidebar

Related Questions

I am just new to programming in Unix and have a small issue that
everything is working fine with my jqgrid except a small issue. i have defined
I have a small issue, I had my SIP client working, and I changed
hey guys, i have very small issue please see the code below // this
I have a small issue with the Code Analysis in Visual Studio 2010. I'm
I am working on an Android opengl lib and have hit a small issue.
I have small issue and that is I am now working with toggle button
I just started to using sass/scss and i have a small issue. Let's assume
I´ve just started using ASIHTTPRequest for iOs and I have a small issue with
can anyone help, i have a small issue, i have an interface and also

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.