1

我刚刚在我的应用程序中添加了 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 Connect,并显示“准备提交”。那么这里应该没问题吧?此外,我在同一个网站上收到警告说我必须提交我的应用程序的新版本才能让应用程序购买正常工作。我决定先提交我的应用程序并在应用程序中禁用 iAP,然后在以后的更新中发布 iAP。是否需要提交新版本来测试 iAP?

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

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

4

1 回答 1

1

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

于 2013-10-07T10:32:06.123 回答