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

request: の完全なバンドル ID の代わりに@"com.mobice.wtm.5010"@"5010". たとえばcom.example.somerandomapp.track01、次のコードが機能する製品があります。

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

エラーにつながる可能性のあるさまざまな要因がたくさんあります。これは、失敗につながる可能性のあるものの良いリストです。

于 2012-06-21T06:08:20.373 に答える