我有一个用于“保存功能”的非消耗性 IAP。它最近被拒绝了,因为我没有在应用程序中包含恢复功能。我添加了恢复代码,但是当我创建一个尚未购买应用程序的新测试用户并按下恢复按钮时,保存功能被解锁。
这是我检查用户是否购买了保存功能的方法
if (![userDefaults boolForKey:@"isPurchase"]){
[self purchaseMyProduct:[validProducts objectAtIndex:0]];
}
else { ... }
这些是我添加的用于恢复 IAP 的方法。
- (void)restorePurchases { //called when button pressed
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
}
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
for (SKPaymentTransaction *transaction in queue.transactions) {
NSString *productID = transaction.payment.productIdentifier;
if ([productID isEqualToString:@"facePuppetsSave"]) {
NSLog(@"called");
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:@"isPurchase"];
[userDefaults synchronize];
}
}
}
这是我已经拥有的方法。
-(void)paymentQueue:(SKPaymentQueue *)queue
updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
break;
case SKPaymentTransactionStatePurchased:
if ([transaction.payment.productIdentifier
isEqualToString:@"facePuppetsSave"]) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setBool:YES forKey:@"isPurchase"];
[userDefaults synchronize];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
@"Purchase completed. Saving now available." message:nil delegate:
self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alertView show];
[alertView release];
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Restored ");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
break;
default:
break;
}
}
}
-(void)productsRequest:(SKProductsRequest *)request
didReceiveResponse:(SKProductsResponse *)response
{
SKProduct *validProduct = nil;
int count = [response.products count];
if (count>0) {
validProducts = response.products;
[validProducts retain];
validProduct = [response.products objectAtIndex:0];
}
此外,对于新的测试用户示例,我注意到从该paymentQueueRestoreCompletedTransactionsFinished
方法“调用”的 NSLog 被调用了两次,并且paymentQueue:updatedTransactions:
根本没有调用从该方法“恢复”的 NSLog。
如何修改我的代码以正确恢复?