Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用程序因未包含“”而被拒绝;“恢复”;购买功能_Ios_Objective C_In App Purchase_Restore - Fatal编程技术网

Ios 应用程序因未包含“”而被拒绝;“恢复”;购买功能

Ios 应用程序因未包含“”而被拒绝;“恢复”;购买功能,ios,objective-c,in-app-purchase,restore,Ios,Objective C,In App Purchase,Restore,我的应用因未实现“恢复购买”功能而被拒绝 苹果说 我们发现您的应用提供了可恢复的应用内购买 但它不包括允许用户恢复的“恢复”功能 以前购买的应用程序内购买。还原 购买应用内购买产品时,应适当提供 “还原”按钮,并在“还原”按钮启动时启动还原过程 按钮被轻敲 所以我最终决定添加它,我发现我们必须使用 [[SKPaymentQueue defaultQueue] restoreCompletedTransactions]; 但这没用! 我搜索了类似的问题,但没有找到适合我的应用程序的问题。 到目前

我的应用因未实现“恢复购买”功能而被拒绝

苹果说

我们发现您的应用提供了可恢复的应用内购买 但它不包括允许用户恢复的“恢复”功能 以前购买的应用程序内购买。还原 购买应用内购买产品时,应适当提供 “还原”按钮,并在“还原”按钮启动时启动还原过程 按钮被轻敲

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

[[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){}
    }
}

中国视频播放应用爱奇艺中的“恢复购买”按钮样式


顺便说一句,您需要一个可见的“恢复按钮”,而不仅仅是我添加的自动恢复眼睛的代码!!
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){}
    }
}