我正在模拟在iPhone上的应用程序中购买自动续订订阅.我的问题是,购买被认为是由App商店完成的,而不是.
这是发生了什么:
>用户按下按钮以购买续订订阅
>用户提供其iTunes密码并确认购买
>该应用程序将从应用商店收到的收据提交给我的服务器以检查有效性
>服务器返回“ok”或“not ok”字符串.应用程序仅在“ok”上调用finishTransaction
我在第3步出现网络故障时遇到问题.我无法验证收据.但是如果用户试图再次购买,应用商店会告诉他他已经订阅了,即使我没有调用finishTransaction方法来完成购买!
这是预期的行为吗? app-store不应该将未完成的交易视为未完成,或者我错过了什么?
我欢迎任何解决这个问题的建议.
-(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"); }