应用内购买失败的交易

时间:2012-09-08 15:41:54

标签: iphone objective-c ios ios4 in-app-purchase

我在我的应用程序中使用应用内购买,完全可以使用。但是在测试之前一切都很顺利。当我输入测试用户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];
}

我犯了什么错误?

1 个答案:

答案 0 :(得分:2)

我在模拟器上测试它。应用程序内部无法正常工作。有必要在设备上进行测试。