Question

Well my problem is simple when trying to make an in app purchase in the simulator the response.products count always returns 0 therefore no purchase... I have been trying to debug it but with no success.... here is the code:

- (IBAction)buy500Coins:(id)sender {

[buyingAI startAnimating];

if (internetActive == NO) {

    [buyingAI stopAnimating];

    askToPurchase = [[UIAlertView alloc]
                     initWithTitle:@"No internet connection"
                     message:@"It seems you are not connected to the internet. in-app purchases require a internet connection. Please connect to the internet and try again."
                     delegate:nil
                     cancelButtonTitle:@"OK"
                     otherButtonTitles:nil, nil];


    [askToPurchase show];


} else {

    askToPurchase = [[UIAlertView alloc]
                     initWithTitle:@"Are you Sure?"
                     message:@"Are you sure you want to buy 4000 coins for 0.99$?"
                     delegate:self
                     cancelButtonTitle:@"No"
                     otherButtonTitles:@"Yes", nil];

    askToPurchase.delegate = self;

    [askToPurchase show];

    [buyingAI stopAnimating];

      }
   }

   -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {



if (alertView == askToPurchase) {
    if (buttonIndex == 1) {
        if ([SKPaymentQueue canMakePayments]) {

            SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"com.ge0rges.Meme_jump.500C"]];



            request.delegate = self;

            [request start];

            [buyingAI startAnimating];
            buyingAI.hidden = NO;

        } else {

            UIAlertView *tmp = [[UIAlertView alloc]
                                initWithTitle:@"Prohibited"
                                message:@"Sorry , Parental Control is enabled, you cannot make a purchase."
                                delegate:nil
                                cancelButtonTitle:@"Ok"
                                otherButtonTitles:nil, nil];
            [tmp show];  

        }  

    }  

}
}

 -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response

{
   [buyingAI stopAnimating];


SKProduct *validProduct = nil;

int count = [response.products count];
NSLog(@"%i", count);
if (count>0) {

    validProduct = [response.products objectAtIndex:0];

    SKPayment *payment = [SKPayment paymentWithProduct:validProduct];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];

    [[SKPaymentQueue defaultQueue] addPayment:payment]; // <-- KA CHING!





} else {

    UIAlertView *notAvail = [[UIAlertView alloc]
                             initWithTitle:@"Not Available"
                             message:@"Sorry there seems to be a problem. Please try again later."
                             delegate:nil
                             cancelButtonTitle:@"Ok"
                             otherButtonTitles:nil, nil];

    [notAvail show];

  }
}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
   for (SKPaymentTransaction *transaction in transactions) {
       switch (transaction.transactionState) {
          case SKPaymentTransactionStatePurchasing:
        {
            [buyingAI startAnimating];
            buyingAI.hidden = NO;

            break;
        }

        case SKPaymentTransactionStatePurchased:
        {

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            [buyingAI stopAnimating];

            UIAlertView *complete = [[UIAlertView alloc]
                                     initWithTitle:@"Complete"
                                     message:@"You have received 4000 Coins."
                                     delegate:nil
                                     cancelButtonTitle:@"Awesome!"
                                     otherButtonTitles:nil, nil];
            [complete show];


            allCoins += 4000;

            break;
        }

        case SKPaymentTransactionStateRestored:
        {

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            [buyingAI stopAnimating];

            break;
        }

        case SKPaymentTransactionStateFailed:
        {

            if (transaction.error.code != SKErrorPaymentCancelled) {

                UIAlertView *failed = [[UIAlertView alloc]
                                       initWithTitle:@"Failed"
                                       message:@"Oops there seems to be a problem. Please   try again later and make sure your internet connection is active."
                                       delegate:nil
                                       cancelButtonTitle:@"Ok :("
                                       otherButtonTitles:nil, nil];
                [failed show];

            }
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            [buyingAI stopAnimating];

               break;
            }
        }
    }
}
Was it helpful?

Solution

Had to make sure the identifier was correct it was misspelled.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top