在iTunes Connect上,使用测试账户进行应用内购买的恢复功能是否有效?

3
购买功能完美运作。但是从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密码。

当您输入您的Apple ID密码时会发生什么? - Paulw11
1
在开发过程中,使用测试账户进行还原操作应该可以正常工作。 - rmaddy
测试账户在App Store上似乎出现了问题,恢复功能在所有使用测试账户的设备上都无法正常工作。有人可以检查一下吗? - Dmitry
2
也许您不小心在沙盒之外使用了测试账户,这会使测试用户失效并且无法正常工作。测试用户 - Jonathan Cichon
您尝试恢复哪种应用内购买? - Tomusm
显示剩余3条评论
2个回答

1
我发现了问题。我有两个非消耗性应用内购买项目。其中一个被移除了,另一个仍然有效。以下代码只返回已被移除的应用内购买项目:
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

所以,问题出在应用商店上...

P.S. 当我再次购买时是免费的,因此两个应用内购买确实已经完成。


你能再详细解释一下吗?你是说你无法使用沙盒账户测试恢复应用内购买吗?谢谢! - Joshua Pinter

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];
 }

欢迎!我觉得这会对你有帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接