1

我在我的应用程序中使用应用内购买,完全是消耗品。但是在我测试之前一切都很好。当我输入测试用户 ID 和密码时,它会进入 SKPaymentTransactionStateFailed。
这是我使用的一些代码:

- (void) funcPrepareForPurchasing:(NSString *)stringType
{
if([SKPaymentQueue canMakePayments])
{
    NSLog(@"Parental Controls are disabled");

    SKProductsRequest *pr = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:[NSString stringWithFormat:@"com.Company.AppName.%@", stringType]]];
    pr.delegate = self;
    [pr start];
}
else
{
    UIAlertView *alertviewPR = [[UIAlertView alloc] initWithTitle:@"Parental Controls" message:@"Parental Controls are On" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:NO, nil];
    [alertviewPR show];
}
}

- (void) funcPurchaseBonusScores
{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.Company.AppName.BonusScores"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) funcPurchaseBonusLife
{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"om.Company.AppName.BonusLife"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) funcPurchaseBonusStar
{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"com.Company.AppName.BonusStar2"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
SKProduct *vp = nil;
int count = [response.products count];
NSLog(@"%i", count);
if(count)
    vp = [response.products objectAtIndex:0];
else if(!vp)
    NSLog(@"No Prodacts are available");
}

- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for(SKPaymentTransaction *transaction in transactions)
{
    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchasing:

            NSLog(@"yidulobs = purchasing");
            break;

        case SKPaymentTransactionStatePurchased:

            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            userDefaultsInApps = [NSUserDefaults standardUserDefaults];
            if( intInApps == 1 )
                [userDefaultsInApps setInteger:5 forKey:@"keyScores"];
            else if( intInApps == 2 )
                [userDefaultsInApps setInteger:5 forKey:@"keyLife"];
            else if( intInApps == 3 )
                [userDefaultsInApps setInteger:5 forKey:@"keyStar"];
            [userDefaultsInApps synchronize];

            NSLog(@"gadaixada");

            break;

        case SKPaymentTransactionStateRestored:

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

        case SKPaymentTransactionStateFailed:

            NSLog(@"Error an Cancelled!!!");
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
    }
    }    
    }

然后我尝试使用此功能购买:

- (void) func1
{
    intInApps = 1;
    [self funcPrepareForPurchasing:@"BonusScores"];
    [self funcPurchaseBonusScores];
}
- (void) func2
{
    intInApps = 2;
    [self funcPrepareForPurchasing:@"BonusLife"];
    [self funcPurchaseBonusLife];
}
- (void) func3
{
    intInApps = 3;
    [self funcPrepareForPurchasing:@"BonusStar2"];
    [self funcPurchaseBonusStar];
}

我犯了什么错误?

4

1 回答 1

2

我在模拟器上测试它。应用程序内不起作用。有必要在设备上对其进行测试。

于 2012-09-09T21:13:06.753 回答