iOS应用内购买永远不会完成 [英] iOS in-app purchase never completes
问题描述
我正在尝试为我的应用创建应用内购买,但我遇到了问题。付款流程开始,用户必须输入密码;但是,付款从未真正完成。我知道我在iTunesconnect中设置了正确的标识符,我还创建了一个测试帐户来购买应用内购买。
I am trying to create an in-app purchase for my app, but I am running into issues. The payment process starts, and the user has to enter in their password; however, the payment never actually completes. I know I have the right identifier set up in iTunesconnect, and I also created a test account to buy the in-app purchase with.
当我运行下面的代码时,我收到以下消息:
When I run the code below, I get the following messages outputted:
用户可以付款
产品可用
交易状态 - >购买
输入我的密码后,系统会提示我确认我的In-App在Sandbox环境中购买。我点击购买,提示消失;但是我从来没有得到实际购买的消息。只是没有任何反应。没有启用附加组件,没有。这在模拟器和实际设备上都会发生。但是,如果我按取消而不是购买,我会收到交易状态 - >已取消消息。
After entering in my password, I am prompted to confirm my In-App Purchase in the Sandbox Environment. I click buy, and the prompt disappears; however I never get the actual purchased message. It's just that nothing happens. No enabling of the add-on, nothing. This happens on both the simulator and actual device. However, if I press cancel instead of buy, I get the "Transaction state -> Cancelled" message.
知道我做错了吗?
- (void)buyTapped {
if ([SKPaymentQueue canMakePayments]) {
NSLog(@"User can make payments");
SKProductsRequest *productRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kLineColorProductIdentifier]];
[productRequest setDelegate:self];
[productRequest start];
}
else {
NSLog(@"User cannot make payments");
}
}
#pragma mark - SKProductsRequestDelegate
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
validProduct = nil;
int count = (int)[response.products count];
if (count > 0) {
validProduct = [response.products objectAtIndex:0];
NSLog(@"Products are available");
SKPayment *payment = [SKPayment paymentWithProduct:validProduct];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
else if (!validProduct)
{
NSLog(@"Product not available");
}
}
- (void)restore {
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSLog(@"received restored transactions: %lu", (unsigned long)queue.transactions.count);
for(SKPaymentTransaction *transaction in queue.transactions){
if(transaction.transactionState == SKPaymentTransactionStateRestored){
//called when the user successfully restores a purchase
NSLog(@"Transaction state -> Restored");
[self enableLineColors];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
//[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
switch(transaction.transactionState){
case SKPaymentTransactionStatePurchasing:
NSLog(@"Transaction state -> Purchasing");
break;
case SKPaymentTransactionStatePurchased:
[self enableLineColors];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction state -> Purchased");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Transaction state -> Restored");
[self enableLineColors];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if(transaction.error.code == SKErrorPaymentCancelled){
NSLog(@"Transaction state -> Cancelled");
//the user cancelled the payment ;(
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateDeferred:
NSLog(@"Transaction state -> Deferred");
}
}
}
推荐答案
好的,昨天和我的另一个应用程序有完全相同的问题。这样做。
Ok, I had the exact same problem yesterday with another app of mine. Do this.
- 在您的实际设备上启动App Store
- 转到推荐标签
- 一路走来在底部将Apple ID更改为您的测试ID
- 当您这样做时,可能会出现另一个窗口。这个窗口出现给我并告诉我我需要添加我的实际信用额度卡片安全代码,更新我的测试帐户的到期日期。
- 我还需要接受我的测试帐户的条款和条件。
- 一次我做到了,然后点击确定。我在实际设备上启动了我的应用程序并重新尝试了应用程序内购买并且它有效。
- Launch App Store on your actual device
- Go to featured tab
- All the way at the bottom change your Apple ID to your test ID
- When you do that then maybe another window that may appear. This one appeared for me and told me that I needed to add my actual credit card security code, update expiration date for my test account.
- I also needed to accept terms and conditions for my test account.
- Once I did that and hit ok. I launched my app on the actual device and retried in-app purchase again and it worked.
出于某些奇怪的原因,如果有像你的测试帐户那样的问题,而不是我的应用内购买失败。
For some bizarre reason if there is a problem like that with your test account instead of failing my in-app purchases just hung.
这篇关于iOS应用内购买永远不会完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!