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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:34:41+00:00 2026-06-03T22:34:41+00:00

This is the edited form using Apple’s doc and as advised. i created 2

  • 0

This is the edited form using Apple’s doc and as advised.
i created 2 separate buttons with 2 separate IBAction.

UIButton *buyCredit1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buyCredit1.frame = scrollViewFrame;
    [buyCredit1 setTitle:@"A bundle of 10 credits - 99¢" forState:UIControlStateNormal];
    buyCredit1.tag = 10;
    [scrollView addSubview:buyCredit1];
    [buyCredit1 addTarget:self
                   action:@selector(purchase10credit:)
         forControlEvents:UIControlEventTouchUpInside];

UIButton *buyCredit2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buyCredit2.frame = scrollViewFrame;
    [buyCredit2 setTitle:@"A bundle of 30 credits - 1.99¢" forState:UIControlStateNormal];
    buyCredit2.tag = 30;
    [scrollView addSubview:buyCredit2];
    [buyCredit2 addTarget:self
                   action:@selector(purchase30credit:)
         forControlEvents:UIControlEventTouchUpInside];

-(IBAction)purchase10credit:(id)sender{
    SKMutablePayment *payment = [[SKMutablePayment alloc] init];
    payment.productIdentifier = @"Bundle.10.credits";

    [[SKPaymentQueue defaultQueue] addPayment:payment];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(IBAction)purchase30credit:(id)sender{
    SKMutablePayment *payment = [[SKMutablePayment alloc] init];
    payment.productIdentifier = @"Bundle.30.credits";

    [[SKPaymentQueue defaultQueue] addPayment:payment];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if (count > 0) {
        validProduct = [response.products objectAtIndex:0];
    }
    else if (!validProduct) {
        NSLog(@"No Products Available");
    }
}

This is the documentation as reflected by Apple for the in-app purchase

-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if (count > 0) {
        validProduct = [response.products objectAtIndex:0];
    }
    else if (!validProduct) {
        NSLog(@"No Products Available");
    }
}
- (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) updateCredit: (NSString *)productIdentifier { 
    //Adding to plist
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; 

    NSMutableArray *currPlist = [[NSMutableArray alloc] initWithContentsOfFile: path];

    NSString *lastEx = [currPlist objectAtIndex:0];
    int lastScore = [[currPlist objectAtIndex:1] intValue];
    int numberOfTries = [[currPlist objectAtIndex:2] intValue];
    int totalScore = [[currPlist objectAtIndex:3] intValue];
    int avg = [[currPlist objectAtIndex:4] intValue];
    int credit = [[currPlist objectAtIndex:5] intValue];

    credit += 10;


    NSString *currentCredit = [NSString stringWithFormat:@"%d credits",credit];
    creditShow.text = currentCredit;

    NSMutableArray *updatePlist = [[NSMutableArray alloc] init];
    [updatePlist addObject:lastEx];
    [updatePlist addObject:[NSNumber numberWithInt:lastScore]];
    [updatePlist addObject:[NSNumber numberWithInt:numberOfTries]];
    [updatePlist addObject:[NSNumber numberWithInt:totalScore]];
    [updatePlist addObject:[NSNumber numberWithInt:avg]];
    [updatePlist addObject:[NSNumber numberWithInt:credit]];
    [updatePlist writeToFile: path atomically:YES]; 
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
    // Your application should implement these two methods.
    [self updateCredit:transaction.payment.productIdentifier];

    // Remove the transaction from the payment queue.
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}


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

    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}


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

In the – (void) updateCredit: (NSString *)productIdentifier, how do i create 2 separate credit update? One for credit += 10 (for the purchase of 0.99¢ and credit += 30 (for the $1.99)?

  • 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-03T22:34:42+00:00Added an answer on June 3, 2026 at 10:34 pm

    Check the (id)sender in your purchase: and determine which button was pressed (You can set up tag property for your buttons, for example tag=1 for 10 credits and tag=5 for 50 credits). Then you can set another in-app purchase:

    UIButton *tempButton = (UIButton *)sender;
    if (tempButton.tag == 1)
    payment.productIdentifier = @"Bundle.10.credits";
    else
    payment.productIdentifier = @"Bundle.50.credits";
    

    As for updating the state that is the recommmended way:

    - (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) completeTransaction: (SKPaymentTransaction *)transaction
    {
        // 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
    {
        [self recordTransaction: transaction];
        [self provideContent: transaction.originalTransaction.payment.productIdentifier];
        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    }
    
    
    - (void) failedTransaction: (SKPaymentTransaction *)transaction
    {
        if (transaction.error.code != SKErrorPaymentCancelled) {
            // Optionally, display an error here.
        }
        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    }
    

    The correct realization of In-App Purchase is available in Apple official In-App Purchase Programming Guide.

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

Sidebar

Related Questions

I'm using Wamp 2.2, edited conf/extra/httpd-vhosts.conf edited this file to add VirtualHosts , but
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
this is my scenario... In a form, i am using some jquery edit in
i have problem with using a method of a form in another form EDITED:
I am trying to scrape form field IDs using Beautiful Soup like this for
This is mostly for radio buttons but; what would happen if you edited the
I'm creating a line which can be edited using this code: var line_points =
I edited this question after i found a solution... i need to understand why
I've edited this quite a bit and bolded my question at this point. I
Warning: This question has been heavily edited. I tried my best to guess the

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.