gpt4 book ai didi

iOS 应用内购买永远不会完成

转载 作者:可可西里 更新时间:2023-11-01 06:06:06 24 4
gpt4 key购买 nike

我正在尝试为我的应用创建应用内购买,但我遇到了问题。付款过程开始,用户必须输入密码;然而,付款从未真正完成。我知道我在 iTunesconnect 中设置了正确的标识符,并且我还创建了一个测试帐户来购买应用内购买。

当我运行下面的代码时,会输出以下消息:

“用户可以付款”

“有货”

“交易状态->采购”

输入密码后,系统会提示我在沙盒环境中确认我的应用内购买。我点击购买,提示消失;但是我从来没有收到实际购买的消息。只是什么也没有发生。没有启用附加组件,什么都没有。这在模拟器和实际设备上都会发生。但是,如果我按取消而不是购买,我会收到“交易状态 -> 已取消”消息。

知道我做错了什么吗?

- (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");
}
}
}

最佳答案

好的,我昨天在使用我的另一个应用程序时遇到了完全相同的问题。这样做。

  • 在您的实际设备上启动 App Store
  • 转到精选标签
  • 一直在底部将您的 Apple ID 更改为您的测试 ID
  • 当您这样做时,可能会出现另一个窗口。这个为我出现并告诉我我需要添加我的实际信用卡安全代码,更新我的测试帐户的到期日期。
  • 我还需要接受测试帐户的条款和条件。
  • 一旦我这样做并点击确定。我在实际设备上启动了我的应用程序并再次尝试应用程序内购买并且成功了。

出于某种奇怪的原因,如果您的测试帐户出现类似问题,而不是我的应用内购买失败,我就会挂起。

关于iOS 应用内购买永远不会完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30089908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com