iOS 应用内购买从未完成
iOS in-app purchase never completes
我正在尝试为我的应用创建应用内购买,但我 运行 遇到了问题。付款过程开始,用户必须输入密码;然而,付款从未真正完成。我知道我在 iTunesconnect 中设置了正确的标识符,我还创建了一个测试帐户来购买应用内购买。
当我运行下面的代码时,我输出了以下消息:
"User can make payments"
"Products are available"
"Transaction state -> Purchasing"
输入密码后,系统会提示我在沙盒环境中确认应用内购买。我点击购买,提示消失;但是我从来没有收到实际购买的消息。只是什么也没有发生。没有启用附加组件,什么都没有。这在模拟器和实际设备上都会发生。但是,如果我按取消而不是购买,我会收到 "Transaction state -> Cancelled" 消息。
知道我做错了什么吗?
- (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
- 当您这样做时,可能会出现另一个 window。这个为我出现并告诉我我需要添加我的实际信用卡安全代码,更新我的测试帐户的到期日期。
- 我还需要接受测试帐户的条款和条件。
- 一旦我这样做并点击确定。我在实际设备上启动了我的应用程序并再次尝试应用程序内购买并且成功了。
出于某种奇怪的原因,如果您的测试帐户出现类似问题而不是我的应用内购买失败,我就会挂起。
我正在尝试为我的应用创建应用内购买,但我 运行 遇到了问题。付款过程开始,用户必须输入密码;然而,付款从未真正完成。我知道我在 iTunesconnect 中设置了正确的标识符,我还创建了一个测试帐户来购买应用内购买。
当我运行下面的代码时,我输出了以下消息:
"User can make payments"
"Products are available"
"Transaction state -> Purchasing"
输入密码后,系统会提示我在沙盒环境中确认应用内购买。我点击购买,提示消失;但是我从来没有收到实际购买的消息。只是什么也没有发生。没有启用附加组件,什么都没有。这在模拟器和实际设备上都会发生。但是,如果我按取消而不是购买,我会收到 "Transaction state -> Cancelled" 消息。
知道我做错了什么吗?
- (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
- 当您这样做时,可能会出现另一个 window。这个为我出现并告诉我我需要添加我的实际信用卡安全代码,更新我的测试帐户的到期日期。
- 我还需要接受测试帐户的条款和条件。
- 一旦我这样做并点击确定。我在实际设备上启动了我的应用程序并再次尝试应用程序内购买并且成功了。
出于某种奇怪的原因,如果您的测试帐户出现类似问题而不是我的应用内购买失败,我就会挂起。