应用因没有 "Restore" 购买功能而被拒绝

App rejected for not having "Restore" Purchases feature

我的应用因未实现 "Restore Purchases" 功能而被拒绝。

苹果说

We found that your app offers In-App Purchase/s that can be restored but it does not include a "Restore" feature to allow users to restore the previously purchased In-App Purchase/s. To restore previously purchased In-App Purchase products, it would be appropriate to provide a "Restore" button and initiate the restore process when the "Restore" button is tapped.

所以我最终决定添加它,我发现我们必须使用

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

但是没有用! 我搜索了类似的问题,但发现 none 适用于我的应用程序。 这些是我到目前为止堆叠的以下链接:

Restore already bought in-app-purchases on iPhone?

iOS6 - In app purchase with download from Apple server

请帮忙!!提前致谢..

尝试以下操作:

单击“还原”按钮 -->

- (IBAction)retoreinApp:(id)sender
{
    //set  addTransactionObserver to self. 
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}

这将调用

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    UIAlertView *alert ;
    if(queue.transactions.count >0)
    {
        for (SKPaymentTransaction *transaction in queue.transactions)
        {
            NSString *productId = transaction.payment.productIdentifier;

          NSLog(@" ProductIdentifier is %@",productId);
            if([productId isEqualToString:@"com.xy.yourProductId"])
            {//add code to add it to your account
             }
          alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"All your previous transactions are restored successfully." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

  }
    else
    {
        alert = [[UIAlertView alloc ] initWithTitle:@"Restore Transactions" message:@"No transactions in your account to be restored." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    }
    [alert show];

}

更新@user4936766 对 Swift 5

的回答
import StoreKit

class ViewController: UIViewController {

    @IBAction func retoreinApp(_ sender: UIButton) {

        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().restoreCompletedTransactions()
    }
}

extension ViewController: SKPaymentTransactionObserver{

    func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { }

    func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) { }

    func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
        var alert: UIAlertController!
        if(queue.transactions.count > 0){
            for transaction in queue.transactions{
                 let productId = transaction.payment.productIdentifier
                 print(" ProductIdentifier is \(productId)")
                 if productId == "com.xy.yourProductId"{
                    //add code to add it to your account
                 }
            }
            alert = UIAlertController(title: "Restore Transactions", message: "All your previous transactions are restored successfully.", preferredStyle: UIAlertController.Style.alert)
         }
         else{
            alert = UIAlertController(title: "Restore Transactions", message: "No transactions in your account to be restored.", preferredStyle: UIAlertController.Style.alert)
         }
         let cancel = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
         alert.addAction(cancel)
         present(alert, animated: true){}
    }
}

中文视频播放应用中的"Restore Purchase"按钮样式爱奇艺.