13

不幸的是,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. 检查用户是否已经购买(用户必须输入用户名和密码)
  3. 如果用户已经购买,则恢复
  4. 如果用户还没有购买,提示支付(用户必须再次输入密码)。

这种方法的问题是: 1. 额外的服务器调用 2. 用户必须输入两次详细信息。

有没有人真正实现了他们可以演示的恢复按钮?

4

4 回答 4

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
于 2012-06-20T05:30:42.213 回答
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);
    }
}
于 2012-06-20T10:27:09.170 回答
0

Apple 拒绝带有 In App Purchase 的应用程序,该应用程序没有恢复购买按钮。在应用视图中,添加一个恢复按钮。然后在 In App Purchase 帮助器类中,添加以下方法:

- (void)restoreCompletedTransactions {
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; 
}

现在从按钮单击操作中调用此方法,它将恢复以前的购买。

于 2014-04-29T05:15:12.980 回答
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);
    }
}*
于 2015-01-24T09:56:23.543 回答