ios 6 InApp购买SKPaymentTransaction剂量不工作方法

时间:2013-03-19 06:41:10

标签: ios6 in-app-purchase in-app-billing storekit xcode4.6

我正在使用以下代码:

但错误是:在案例SKPaymentTransactionStateRestored的情况下,案例处于受保护的范围内: 也 案例SKPaymentTransactionStateFailed: 和
默认值:

有人解决了这个问题吗?

先谢谢你。

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

    for (SKPaymentTransaction *transaction in transactions)
 {
        switch (transaction.transactionState)

        {
            case SKPaymentTransactionStatePurchasing:
                                 //[self completeTransaction:transaction];
                // show wait view here
                statusLabel.text = @"Processing...";
                break;

            case SKPaymentTransactionStatePurchased:

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view and unlock feature 2
                statusLabel.text = @"Done!";
                UIAlertView *tmp = [[UIAlertView alloc]
                                    initWithTitle:@"Complete"
                                    message:@"You have unlocked Feature 2!"
                                    delegate:self
                                    cancelButtonTitle:nil
                                    otherButtonTitles:@"Ok", nil];
                [tmp show];



                NSError *error = nil;
                [SFHFKeychainUtils storeUsername:@"IAPNoob01" andPassword:@"whatever" forServiceName:kStoredData updateExisting:YES error:&error];

                // apply purchase action  - hide lock overlay and
                [feature2Btn setBackgroundImage:nil forState:UIControlStateNormal];

                // do other thing to enable the features

                break;

   case SKPaymentTransactionStateRestored: //ERROR:- Switch case is in protected scope

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

                // remove wait view here
                statusLabel.text = @"";

                break;

 case SKPaymentTransactionStateFailed: //ERROR:- Switch case is in protected scope

                if (transaction.error.code != SKErrorPaymentCancelled)
            //    [self failedTransaction:transaction];
                {
                    NSLog(@"Error payment cancelled");
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view here
                statusLabel.text = @"Purchase Error!";
                break;

          default:  //ERROR:- Switch case is in protected scope

                break;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您应该使用{}

附上案例

示例:

    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchasing:
            {
                //[self completeTransaction:transaction];
                // show wait view here
                statusLabel.text = @"Processing...";
                break;
            }
        case SKPaymentTransactionStateFailed:
            {
                // another case contents
                break;
            }
    }