我在iPhone上模拟我的应用程序中自动更新订阅的购买。我的问题是,购买被认为是由应用程序商店,而不是。
下面是正在发生的事情:
当第三步发生网络故障时,我有问题。我无法验证收据。但是如果用户第二次尝试购买,应用程序商店告诉他他已经订阅了,即使我没有调用finishTransaction方法来完成购买!
这是一种预期的行为吗?应用商店不应该把未完成的事务当作未完成的事务处理,还是我遗漏了什么?我欢迎任何解决这个问题的建议。
-(void) userPurchase:(SKProduct*) product{
SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
NSLog(@"paymentQueue updatedTransaction");
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
[self recordSubscription:transaction];
break;
case SKPaymentTransactionStateFailed:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self recordSubscription:transaction];
break;
default: NSLog(@"Default");
break;
}
};
}
-(void) recordSubscription:(SKPaymentTransaction*)transaction{
NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithObjectsAndKeys:jsonObjectString,@"receiptdata", nil];
[[AFNetworkSubClass sharedClient] postPath:@"myserver" params:params
success:^(AFHTTPRequestOperation *operation, id output) {
/* some code */
if([valstring isEqualToString:@"ok"]){
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
}
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"validation failed");
}发布于 2013-11-27 08:40:11
我认为在调用recordSubscription方法之前,您可以调用finish finishTransaction方法从支付队列中删除付款,因为您已经完成了与苹果服务器的购买操作。
如果网络故障使您无法验证应用程序接收,只需记录收据并将收据再次验证到您自己的服务器,或者在下次网络可访问时验证。
我希望它能帮到你。
发布于 2013-11-29 04:50:53
用户不能购买相同的订阅,直到它到期。在您的情况下,采购事务已经完成,但由于网络故障,您没有提供服务。我以前也有类似的问题。您可能需要要求用户恢复所有已完成的事务。
然后调用completeTransaction函数。祝好运!
发布于 2016-07-08 08:52:29
如果您没有调用finishTransaction,这并不意味着事务没有从用户那里获得金钱。所有这些调用都是防止StoreKit在每次启动时通知应用程序事务。这只是告诉StoreKit您已经完成了事务的一种方式,即解锁用户内容并将其保存到后端等。
因此,即使出现网络错误,您也应该重新尝试API调用。如果您关闭了应用程序并重新打开,您应该得到一个事务更新,以表明它是“购买”的,让您有时间再次提交到服务器:)
这是预期的行为,否则您将是双/三计费用户。
https://stackoverflow.com/questions/20066553
复制相似问题