1

这是代码:

-(IBAction)purchase5010:(id)sender{

    productUserRequests = 0;
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.mobice.wtm.5010"];
    [[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:productUserRequests];
    }else if(!validProduct){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No products available at this time." 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [self dismissModalViewControllerAnimated:YES];
    }
}

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if (count > 0) {
    validProduct = [response.products objectAtIndex:productUserRequests];
    }else if(!validProduct){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No products available at this time." 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    [self dismissModalViewControllerAnimated:YES];
    }
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for (SKPaymentTransaction *transaction in transactions) {
    switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchasing:

            break;
        case SKPaymentTransactionStatePurchased:
            if (productUserRequests == 0) {
                NSString *hints = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Hints"]];
                int hintValue = [hints intValue];
                hintValue+=50;
                [hints release];
                hints = [[NSString alloc]initWithFormat:@"%i", hintValue];
                [hints writeToFile:[self pathOfFile:@"Hints"] atomically:YES];

                NSString *reveals = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Reveals"]];
                int revealValue = [reveals intValue];
                revealValue+=50;
                [reveals release];
                reveals = [[NSString alloc]initWithFormat:@"%i", revealValue];
                [reveals writeToFile:[self pathOfFile:@"Reveals"] atomically:YES];


            }else if(productUserRequests == 1){
                NSString *hints = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Hints"]];
                int hintValue = [hints intValue];
                hintValue+=150;
                [hints release];
                hints = [[NSString alloc]initWithFormat:@"%i", hintValue];
                [hints writeToFile:[self pathOfFile:@"Hints"] atomically:YES];

                NSString *reveals = [[NSString alloc]initWithContentsOfFile:[self pathOfFile:@"Reveals"]];
                int revealValue = [reveals intValue];
                revealValue+=20;
                [reveals release];
                reveals = [[NSString alloc]initWithFormat:@"%i", revealValue];
                [reveals writeToFile:[self pathOfFile:@"Reveals"] atomically:YES];
            }
    case SKPaymentTransactionStateFailed:
            if (transaction.error.code != SKErrorPaymentCancelled) {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"In-app purchase failed. No money was charged." 
                                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alert show];
                [alert release];

            }
            [[SKPaymentQueue defaultQueue]finishTransaction:transaction];
            break;
    }
    }
}

现在,每当我尝试购买该商品时,它都会显示“目前没有可用的产品。”以及“应用内购买失败。没有收取任何费用。” 我想知道,上面的代码有问题吗?还是更可能是iTunes连接问题?

4

1 回答 1

0

而不是请求的完整捆绑ID:,@"com.mobice.wtm.5010"继续并只提供一个@"5010". 例如,我有一个产品com.example.somerandomapp.track01,以下代码有效:

SKPayment *paymentRequest = [SKPayment paymentWithProductIdentifier: @"track01"]; 

有很多不同的因素会导致错误,这是一个很好的列表,列出了可能导致失败的原因

于 2012-06-21T06:08:20.373 回答