【发布时间】:2016-01-08 11:49:15
【问题描述】:
据我所知,Apple 建议获取购买和恢复按钮(我在应用程序的设置视图中有这些),在其他视图中我只有购买按钮。
当用户点击“购买”按钮时,苹果检测到该用户已经购买了该产品,他会要求用户免费恢复此次购买(这里一切正常)。当用户单击“是”时,将调用 updateTransactions:,并且它始终在 case SKPaymentTransactionStatePurchased: 上,而不是在 case SKPaymentTransactionStateRestored: 上。
这是为什么呢?有没有办法用updatedTransactions: 区分 restore 和 new purchase?
- (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;
}
}
}
【问题讨论】:
标签: ios xcode in-app-purchase