我正在尝试为我的应用创建应用内购买,但我遇到了问题。付款流程开始,用户必须输入密码;但是,付款从未实际完成。我知道我在iTunesconnect中设置了正确的标识符,我还创建了一个测试帐户来购买应用内购买。
当我运行下面的代码时,我会收到以下消息:
"用户可以付款"
"产品可用"
"交易状态 - >采购"
输入我的密码后,系统会提示我在Sandbox环境中确认我的应用程序内购买。我点击购买,提示消失;但是我从来没有得到实际购买的消息。只是没有任何反应。没有启用附加组件,没有。这在模拟器和实际设备上都会发生。但是,如果我按取消而不是购买,我会得到"交易状态 - >取消"消息。
知道我做错了吗?
- (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");
}
}
}
答案 0 :(得分:1)
好的,我昨天和我的另一个应用程序有完全相同的问题。这样做。
出于某些奇怪的原因,如果您的测试帐户出现类似问题而不是我的应用内购买失败,那么就会挂起。