恢复应用内购买是否适用于iTunes Connect上的测试帐户?

时间:2014-06-07 23:07:55

标签: ios in-app-purchase itunesconnect

采购工作完美。但是恢复应用内购买并不适用于iTunes Connect上的测试帐户。这是对的吗?我使用以下代码恢复购买:

... {
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

// called when a transaction has been restored and and successfully completed
- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
    [self recordTransaction:transaction.originalTransaction];
    [self provideContent:transaction.originalTransaction.payment.productIdentifier];
    [self finishTransaction:transaction wasSuccessful:YES];
}

// saves a record of the transaction by storing the receipt to disk
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
    if ([transaction.payment.productIdentifier isEqualToString:[self getProductId:gFullVersion]]) {
        // save the transaction receipt to disk
        [[NSUserDefaults standardUserDefaults] setValue:transaction.transactionReceipt forKey:[self getProductId:gFullVersion]];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
}

// removes the transaction from the queue and posts a notification with the transaction result
- (void)finishTransaction:(SKPaymentTransaction *)transaction wasSuccessful:(BOOL)wasSuccessful {
    // remove the transaction from the payment queue.
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

    NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:transaction, @"transaction" , nil];
    if (wasSuccessful) {
        // send out a notification that we’ve finished the transaction
        [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:userInfo];
    } else {
        // send out a notification for the failed transaction
        [[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionFailedNotification object:self userInfo:userInfo];
    }
}

应用程序显示输入AppleID密码的对话框。

2 个答案:

答案 0 :(得分:1)

我发现了这个问题。我有两个非耗材的应用程序。一个被删除。一个人很活跃。以下代码仅返回在应用内删除:

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

所以,问题出在App Store上......

P.S。当我再次购买时,它是免费的,因此真正制作了两个应用程序。

答案 1 :(得分:0)

我按照此代码执行了“恢复”按钮。

  -(void)restoreButtonTapped{

  [[RMStore defaultStore] restoreTransactionsOnSuccess:^{
                NSLog(@"Restored Successfully");
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                [apDelegate hideLoading];
                BOOL isExpired = [self isPurchaseExpired:[NSDate date]]; // DEV-TODO: again fetching the expireDate from user Defaults in the method, so just sending the current Date.
                if (!isExpired)
                {
                    [self moveToLoginScreen];
                }
                else
                {
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"Product expired, Please buy the product for uninterrupted services." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                    [alert show];
                }
            } failure:^(NSError *error) {
                [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
                NSLog(@"Failed to restore Completed Transactions");
                [apDelegate hideLoading];
                UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"MDPulse" message:@"Failed to restore Transactions. Please try again." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                [alert show];
            }];
        }


  }




   - (void)restoreCompletedTransactions
  {
    NSLog(@"Restore Tapped in transaction process");
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
  }

  - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
  {
NSLog(@"Restore completed transactions finished.");
NSLog(@" Number of transactions in queue: %d", [[queue transactions] count]);
for (SKPaymentTransaction *trans in [queue transactions])
  {
    NSLog(@" transaction id %@ for product %@.", [trans transactionIdentifier], [[trans payment] productIdentifier]);
    NSLog(@" original transaction id: %@ for product %@.", [[trans originalTransaction] transactionIdentifier],
          [[[trans originalTransaction] payment]productIdentifier]);


    if ([[[trans payment] productIdentifier] isEqual: kMDPulseSubscriptionProductIdentifier]) {

        NSLog(@"Purchase Restored");

        // Do your stuff to unlock
    }
  }
  }

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
NSLog(@"%s","User Cancel.");

MedPulseAppDelegate *appdelegate =( MedPulseAppDelegate *)[[UIApplication sharedApplication]delegate];
[appdelegate hideLoading];

}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"restoreTransaction...");

[self validateReceiptForTransaction:transaction];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
 }

欢迎!

我认为这会帮助你。