无法获得SKProductsResponse产品:response.count = 0

时间:2013-10-07 10:03:45

标签: ios in-app-purchase product

我刚刚在我的应用中添加了iAP,但我收到了错误。

- (void)getProductID { //runs on viewdidload
    if ([SKPaymentQueue canMakePayments]) {
        SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:_productID, nil]];
        request.delegate = self;

        [request start];
    } else {
        [[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store. Try enabling in-app-purchases in settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

        [self couldNotConnectToStore];
    }

}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:[self unlockPurchase];
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            case SKPaymentTransactionStateFailed:NSLog(@"Transation Failed");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

            default:break;
        }
    }
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    NSArray *products = response.products;

    if (products.count != 0) {
        _product = products[0];
        _allowPurchase = YES;
    } else {
        [[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];//this line of code runs a second after the controller opens

//****************** error on line above *********************************

        [self couldNotConnectToStore];
    }

    products = response.invalidProductIdentifiers;

    for (SKProduct *product in products) {
        NSLog(@"Product not found: %@", product);
    }
}


- (IBAction)purchaseButtonPressed:(UIButton *)sender {
    if (sender.tag == 1) {
        //buy 20
        _productID = @"com.piguygames.serpentine.buy20";

        SKPayment *payment = [SKPayment paymentWithProduct:_product];
        [[SKPaymentQueue defaultQueue] addPayment:payment];

    } else if (sender.tag == 2) {
        //buy 45
    } else if (sender.tag == 3) {
        //buy 100
    } else if (sender.tag == 4) {
        //double
    } else if (sender.tag == 5) {
        //remove ads
    }
}

注意:控制器中还有一些其他代码,但我认为它不相关。

我已将应用内购买添加到iTunes连接,并显示“已准备好提交”。那么它应该没问题吗?此外,我在同一网站上收到警告说我必须提交我的应用程序的新版本才能进行应用程序购买。我决定先提交我的应用并在应用中禁用iAP,然后在稍后的更新中发布iAP。您是否需要提交新版本来测试iAP?

无论如何,到目前为止你能看到任何问题吗?

如果需要更多信息,请提出更多信息,我是这个主题的初学者。 感谢

1 个答案:

答案 0 :(得分:0)

确保您已从“设置”应用中退出任何iTunes帐户,除非它是您在iTunes Connect中创建的测试帐户。我最近遇到了同样的问题,这就是我解决它的方法。