据我所知Apple推荐购买和恢复按钮(我在我的应用程序的设置视图中有这些),在其他视图中我只有购买按钮 .
当用户点击"Buy"按钮并且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;
}
}
}
1 回答
购买您已经拥有的东西(尽管UIAlert说它正在被恢复)会触发SKPaymentTransactionStatePurchased状态 . SKPaymentTransactionStateRestored状态仅在您执行以下操作时发生: