response.products计数总是返回0 Xcode 4 ios应用程序内购买

时间:2013-08-29 18:46:03

标签: ios xcode in-app-purchase storekit

我的问题很简单,当试图在模拟器中进行应用程序购买时,response.products计数总是返回0因此没有购买...我一直在尝试调试它但没有成功....这里是代码:

- (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;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

如果要确保标识符正确,则拼写错误。