据我所知,Apple要求获得“购买”和“还原”按钮(我在应用程序的设置视图中拥有这些按钮),而在其他视图中,我仅具有“购买”按钮。
当用户单击“购买”按钮并且Apple检测到该用户已经购买了该产品时,他将要求该用户免费恢复此购买(一切都很好)。当用户单击“是”时,就会调用updateTransactions:
,并且它始终在case SKPaymentTransactionStatePurchased:
上而不是在case SKPaymentTransactionStateRestored:
上。
这是为什么 ?有没有办法通过updatedTransactions:
将恢复与新购买区分开?
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
for(SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchasing: //NSLog(@"Transaction state -> Purchasing");
//called when the user is in the process of purchasing, do not add any of your own code here.
break;
case SKPaymentTransactionStatePurchased:
//this is called when the user has successfully purchased the package (Cha-Ching!)
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Purchase" action:@"Purchase Completed!" label:shopNameSelected value:nil] build]];
[self doGoPremium];
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
//NSLog(@"Transaction state -> Purchased");
break;
case SKPaymentTransactionStateRestored:
//NSLog(@"Transaction state -> Restored Here");
//add the same code as you did from SKPaymentTransactionStatePurchased here
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Purchase" action:@"Purchase Restored" label:shopNameSelected value:nil] build]];
[self doGoPremium];
[MBProgressHUD hideHUDForView:self.view animated:YES];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
//called when the transaction does not finnish
[MBProgressHUD hideHUDForView:self.view animated:YES];
if(transaction.error.code != SKErrorPaymentCancelled){
//NSLog(@"Transaction state -> Cancelled");
//the user cancelled the payment ;(
// Add some analytics point.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"Purchase" action:@"Purchase Canceled" label:shopNameSelected value:nil] build]];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
最佳答案
购买您已经拥有的东西(尽管UIAlert表示已恢复)会触发SKPaymentTransactionStatePurchased状态。仅在执行以下操作时才会发生SKPaymentTransactionStateRestored状态:
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
关于ios - iOS InApp购买已更新交易:无法区分新购买和还原,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23981485/