Apple遗憾地拒绝了我的应用程序没有恢复按钮。我希望为用户提供无缝体验,但存在一些问题。
- (void)purchaseProUpgrade
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
// User is prompted for iTunes username and password here (1)
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
// Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
if( queue.transactions.count == 0 ) {
[self setUpgradeProductId];
// User is prompted for iTunes username and password here (2)
SKPayment *payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}else {
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:NULL];
}
}
以上是一个很好的解决方案吗?逻辑是:
这种方法的问题是: 1.另一个服务器调用 2.用户必须输入两次详细信息。
有没有人真正实现了可以演示的“还原”按钮?
答案 0 :(得分:11)
无需实施自己的逻辑 只需实现这个
- (IBAction)restorePreviousTransaction:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
这将调用此方法
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
case SKPaymentTransactionStateRestored:
if ([self respondsToSelector:@selector(restoreTransaction:)]) {
[self restoreTransaction:transaction];
return;
}
这会将这些委托方法称为事务成功或失败
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
答案 1 :(得分:7)
将此代码添加到已添加恢复按钮的页面:
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
NSLog(@"%@",error);
}
// Call This Function
- (void) checkPurchasedItems
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
[purchasedItemIDs addObject:productID];
NSLog(@"%@",purchasedItemIDs);
}
}
答案 2 :(得分:0)
Apple拒绝使用In App Purchase的应用程序,该应用程序没有恢复购买按钮。在应用视图中,添加还原按钮。 然后在In App Purchase帮助程序类中,添加以下方法:
- (void)restoreCompletedTransactions {
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
现在从按钮点击操作调用此方法,它将恢复先前的购买。
答案 3 :(得分:0)
*- (IBAction)restorePreviousTransaction:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
delegate method call:
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
case SKPaymentTransactionStateRestored:
if ([self respondsToSelector:@selector(restoreTransaction:)]) {
[self restoreTransaction:transaction];
return;
}
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %i", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
[purchasedItemIDs addObject:productID];
NSLog(@"%@",purchasedItemIDs);
}
}*