在iOS上测试应用内购买没有错误

时间:2013-12-14 09:47:11

标签: ios iphone in-app-purchase xcode5

这是我在iOS中使用应用内购买的第一个应用。我在测试应用内购买时遇到了困难。这是一个重新设计的游戏,因此功能已经集成。我已准备好将游戏提交给苹果,但我仍然试图确认应用内购买是否正常。

我有一个测试用户帐户我已登录,并且我与测试用户一起购买了 in-app-purchase 。它显示“购买”然后消失,但从来没有购买它的假设?没有错误消息!?功能是假设购买额外的硬币,但这些硬币在“购买”后不会出现。

这是否适用于在应用购买中进行测试?

Reachability* reachability = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [reachability currentReachabilityStatus];
if (internetStatus != ReachableViaWiFi && internetStatus != ReachableViaWWAN) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection" 
                                                    message:@"You require an internet connection via WiFi or cellular network for connecting to online store" 
                                                   delegate:nil 
                                          cancelButtonTitle:@"Dismiss" 
                                          otherButtonTitles:nil];

    [alert show];
    [alert release];
    bErrorOnConnection = YES;
}




if ([SKPaymentQueue canMakePayments])
{
    [self requestProductData];

} else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"In-App Purchases are disabled" 
                                                    message:@"Please check your restrictions for In-App Purchases in Settings->General->Restrictions." 
                                                   delegate:nil 
                                          cancelButtonTitle:@"Dismiss" 
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];
    bErrorOnConnection = YES;
}

- (IBAction) closePressed:(id) sender {
[mainGameParent GameStoreClosed];
[self.view removeFromSuperview];

}

- (IBAction) purchaseUnlock:(id) sender {

bool bPaymentInQueue = NO;
for (SKPaymentTransaction *transaction in [SKPaymentQueue defaultQueue].transactions) {
    if ([transaction.payment.productIdentifier isEqualToString:kPayoutUnlockProduct]) {
        bPaymentInQueue = YES;
        NSLog(@"Payment already in queue!");
        break;
    }
}
if (!bPaymentInQueue) {
    NSLog(@"Adding new payment...");
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:kPayoutUnlockProduct];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}



  (IBAction) restore:(id)sender {
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}

- (IBAction) moreGames:(id)sender {
SurfSlotMachineAppDelegate* del = (SurfSlotMachineAppDelegate*)[UIApplication sharedApplication].delegate;
[del dispMoreApps];

}

- (void)requestProductData {

//lblLoading.hidden = NO;
[activityIndicatorView setHidden:YES];
//[activityIndicatorView startAnimating];

SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kPayoutUnlockProduct]];

NSLog(@"%@",kPayoutUnlockProduct);
request.delegate = self;
[request start];



- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchased:
            NSLog(@"Transaction Purchased");
            [self completeTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            NSLog(@"Transaction Failed");
            [self failedTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
            NSLog(@"Transaction Restored");
            [self restoreTransaction:transaction];
        default:
            break;
    }
}

}

有关如何修复此代码的任何提示?这是一个简单的修复?

1 个答案:

答案 0 :(得分:0)

如果您没有触摸代码,那肯定是行不通的。购买应该能够完成,但你必须实施

- (void)completeTransaction:(SKPaymentTransaction *)transaction

更新用户购买后应获得的内容。