应用程序被拒绝因为没有"恢复"购买功能

时间:2015-05-25 12:35:12

标签: ios objective-c in-app-purchase restore

我的应用因未执行"还原购买而被拒绝"特征

Apple说

  

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

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

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

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

Restore already bought in-app-purchases on iPhone?

iOS6 - In app purchase with download from Apple server

请帮忙!!提前谢谢..

2 个答案:

答案 0 :(得分:3)

尝试以下方法:

在恢复按钮上单击 - >

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

}

答案 1 :(得分:0)

将@ 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){}
    }
}

中文视频播放应用程序 iQiYi 中的“恢复购买”按钮样式。

demo